Home > DeveloperSection > Forums > How to get information from DataList's footer on buttonClick
Ankita Pandey
Ankita Pandey

Total Post:183

Posted on    December-18-2013 1:01 AM

 ASP.Net ASP.Net 

 1 Reply(s)
 1273  View(s)
Rate this:

I have an ASP.NET DataList, with a footer defined thus:


    <asp:DropDownList ID="ddlStatusList" runat="server">


    <input id="txtNotes" type="text" placeholder="Notes" />

    <asp:Button runat="server" type="button" Text="Add" ID="btnAdd"></asp:Button>


What I'm looking to do, is, on click of btnAdd, get the values from txtNotes and ddlStatusList, but I can't work out how to access the controls, let alone the values.

I can't follow something like this because I won't be able to check if my button has been clicked (as is possible with a checkbox), and even then, I'm not sure if I'll be able to use findControl as demonstrated. (Does a DataList's footer behave differently to an item?)

I can't use the Button's commandName & commandValue attributes because, when databound, the text inputted won't exist and therefore I can't set the CommandValue.

I have tried using a LinkButton rather than a normal .NET Button, but come accross the same issue, whereby I cannot work out how to get the values from the TextBox/DropDownList

ezra heywood
ezra heywood

Total Post:145

Posted on    December-18-2013 1:30 AM

Hi Ankita,

You can use Control.NamingContainer to access other controls in a row:


        <asp:DropDownList ID="ddlStatusList" runat="server">


        <input id="txtNotes" type="text" placeholder="Notes" runat="server" />

        <asp:Button runat="server" type="button" Text="Add" ID="btnAdd" OnClick="btnAdd_Click"></asp:Button>


    protected void btnAdd_Click(object sender, EventArgs e)


        Button btnAdd = (Button)sender;

        DropDownList ddlStatusList = (DropDownList)btnAdd.NamingContainer.FindControl("ddlStatusList");

        System.Web.UI.HtmlControls.HtmlInputText txtNotes = (System.Web.UI.HtmlControls.HtmlInputText)btnAdd.NamingContainer.FindControl("txtNotes");

        int index = ddlStatusList.SelectedIndex;

        string text = txtNotes.Value;


Don't want to miss updates? Please click the below button!

Follow MindStick