forum

Home / DeveloperSection / Forums / Change text on button in datalist not working

Change text on button in datalist not working

Anonymous User 2031 18-Dec-2013
I have the following code and it works to change the URL, but it does not change the text on the button. What am I missing?
<asp:Button ID="btnQuizVid" runat="server" Text="Quiz" CommandName="quiz" CssClass="buttonStyleGrey" />
protected void trainingDataList_ItemCommand(object source, DataListCommandEventArgs e)
{
    List<Material> dataset = null;
    string btnText = ((Button)(trainingDataList.Items[e.Item.ItemIndex].FindControl("btnQuizVid"))).Text;
    if (e.CommandName == "quiz")
    {
        dataset = BasicCRUDtoolkit.GetMaterialByProfFocus(hdnTypeSelect.Value);
        Button tmpBtn = e.Item.FindControl("btnQuizVid") as Button;
        if (btnText == "Quiz")
        {
            tmpBtn.Text = "Video";
            tmpBtn.DataBind();
            dataset[e.Item.ItemIndex].videoURL = dataset[e.Item.ItemIndex].quizURL;
        }
        else
        {
            tmpBtn.Text = "Quiz";
            dataset[e.Item.ItemIndex].videoURL = dataset[e.Item.ItemIndex].videoURL;
        }
        trainingDataList.DataSource = dataset;
        trainingDataList.DataBind();
    }
}


The button is in a datalist and I want to change the Text on the button when pressed. What is supposed to happen is the user hits the Quiz button and the URL should change to the quizURL(this works). At the same time the text on the button should change to say Video(this doesn't work). Then when the user hits the same button it will toggle back to the quiz. I'm trying to have one button act as a toggle to show the quiz or the video. 

c# c# 
Updated on 18-Dec-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By