Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi my dear friends,

i would like to change one datalist1 lable text when i am click on another datalist2 button is it possible...? it it is ..how can share that sample link

please help me...i hope u understand my question,thank you

What I have tried:

<asp:DataList ID="datalist1" OnItemCommand="dl_beers_ItemCommand" Width="100%" CellSpacing="10" DataKeyField="pid" ItemStyle-HorizontalAlign="Center" RepeatDirection="Vertical" RepeatColumns="1" RepeatLayout="Table" runat="server">










<asp:DataList ID="datalist2" OnItemCommand="dl_beers_ItemCommand" Width="100%" CellSpacing="10" DataKeyField="pid" ItemStyle-HorizontalAlign="Center" RepeatDirection="Vertical" RepeatColumns="1" RepeatLayout="Table" runat="server">
Posted
Updated 20-Sep-16 6:56am
Comments
Karthik_Mahalingam 16-Sep-16 9:26am    
Not clear, need more info.
in c# or javascript?
j snooze 16-Sep-16 17:48pm    
I'd go javascript, you don't really want to do a postback just to change text on a label from a button click.

1 solution

If you have a Button in your second DataList then you can do something like this (server-side approach):

C#
protected void Button1_Click(object sender, EventArgs e)
{
    Button btn = (Button)sender;
    DataListItem item = (DataListItem)btn.NamingContainer;
    if (item != null)
    {
        //accessing the first Label control within your first DataList
        //You may need to change the index of items based on your requirement
        Label lbl = (Label)DataList1.Items[0].FindControl("YourLabelID");
        lbl.Text = "Some text here";
    }
}
 
Share this answer
 

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