ASP.NET - how to get value of clicked column items from datalist??

Asked By mani on 02-Feb-12 01:27 AM
hi..i have datalist and in each item i have imagebutton and one link buton..i need to get linkbutton text of curresponding  clicked imagebutton in each cell in datalist controll any idea??
Jatin Trikha replied to mani on 02-Feb-12 01:32 AM
If are clicking imagebutton why you need linkbutton. May be its you requirement you can use the commandargument property to save the value while bounding  and use it on image click.

Hope it helps....
mani replied to Jatin Trikha on 02-Feb-12 01:33 AM
i have to click both linkbutton or imagebutton..
Reena Jain replied to mani on 02-Feb-12 01:34 AM

You can use GetElementsByTagName of javascript DOM method to get the controls from tag name, here input is the tag name so it goes like following

function GetChecked()
  var container =  document.getElementById('<% rptCat.ClientID %>');
  var totalInputs = container.getElementsByTagName('input');
  for(var i = 0;i< totalInputs.Length;i++)
  if(totalInputs[i].type.toLowerCase()=='checkbox' && totalInputs[i].checked)
    id += totalInputs[i].id;

this way you can get them
Jatin Trikha replied to mani on 02-Feb-12 01:38 AM
ok,, you can use CommandArgument property both linkbutton and imagebutton have this property which will remain during postback
dipa ahuja replied to mani on 02-Feb-12 03:36 AM
Implement the ItemCommand EVent
<asp:LinkButton ID="linkButton1" CommandName="select" runat="server" Text='<%# Eval("ID") %>' />
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    if (e.CommandName == "select")
      LinkButton l = new LinkButton();
      l= (LinkButton)e.Item.FindControl("linkButton1");