i have made a massenger chat project in C# asp net.
after login, you find any members in a page, where you can send you messages. for this i need to get accdess to controls in datalist, which are image of the suctomer and its name (which is a linkbutton)... when i press linkbutton to get the name, the string variable is empty???!!! i used other option, but it stands the last name in the list of customers???!!!
i attach the codes thanks
/forums/uploadfile/a8d6ef/02022023171459PM/codes.pdf

Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 2, 2023, 10:20 PM EST
Hi Venus,
To get access to controls inside a DataList control in C# ASP.NET, Please try the below code.
DataList control, for example a LinkButton with ID "LinkButton1".
' CommandName="Select">In the code-behind, you can access the control in the ItemDataBound event of the DataList:
protected void dlCustomers_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { LinkButton lbName = (LinkButton)e.Item.FindControl("LinkButton1"); // Perform operations on the LinkButton control } }For handle the Click event of the LinkButton control, you can add a Command event handler to the DataList control:
protected void dlCustomers_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "Select") { LinkButton lbName = (LinkButton)e.Item.FindControl("LinkButton1"); string name = lbName.Text; // Perform operations on the selected name } }Thanks
Naimish Makwana