Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have a ajaxtabcontainer control in my project which contains a datalist and in datalist i have set the names as link button. The datalist that i am binding to a source is containing Names and age. Now i want to use the age as selected value like we use in dropdownlist selected value? what i want is on clicking the name link button i get its value inside a label? how to do it? what i have done is as follows: in Default aspx:
XML
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </ajaxToolkit:ToolkitScriptManager>
    <ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1">
        <ajaxToolkit:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
            <HeaderTemplate>
               Names
            </HeaderTemplate>
         <ContentTemplate>
        <asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="5" ForeColor="Red"
            RepeatLayout="Table" >

              <ItemTemplate>
              <asp:LinkButton Text = '<%#Eval("names")%>' ID="lnkpro" runat="server" ForeColor="Red" OnClick="btn_Click"></asp:LinkButton>
              </ItemTemplate>
            </asp:DataList>

        </ContentTemplate>

    </ajaxToolkit:TabContainer>

in cs code:
protected void btn_Click(object sender, EventArgs e)
    {

        LinkButton myButton = sender as LinkButton;
        if (myButton != null)
        {
            Label1.Text = myButton.Text;
        }

    }
    protected void datalist1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        int i;
        int index = Convert.ToInt32(e.Item.ItemIndex);
        LinkButton lnkid = (LinkButton)e.Item.FindControl("lnkpro");
        Label1.Text = lnkid.Text;
        i = Convert.ToInt32(lnkid.Text);
    }

but they are not working. the btn_click is working but giving only name not its id. the second datalist_itemcommand is not working? Thank you.
Posted
Comments
Er Daljeet Singh 21-Nov-13 2:36am    
first thing in if you try to find the id of linkbutton through btn_Click() you will get same Id.
second the in datalist you have not mentioned the onitemcommand="DataList1_ItemCommand" in you HTML page thats why it is not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900