Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid - Index of the row/column Clicked

Status
Not open for further replies.

DilipKS

Programmer
Mar 8, 2004
30
CH
Hi
with the DataGrid control in ASP .NET , is there any property we can get the index of row clicked ?

If you have standard events like below , you can get it
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int rowNum = e.Item.ItemIndex;
}

but what if i want to use some other function say
private void userdefinedfunc()
{
}
how do i get the index of selected row when i dont have DataGridItemEventArgs object ?
 
I don't use c# so the syntax might be off

Code:
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int rowNum = e.Item.ItemIndex;
// think ctype doesn't exsist in j# could use
// CType(e.Item.FindControl("yourControlThatClicksAndFiresAnEventWhereYouNeedTheIndex"), whatever).attributes.add("myIndex",rowNum)
//or
whatever mycontrol = (whatever) e.Item.FindControl("yourControlThatClicksAndFiresAnEventWhereYouNeedTheIndex")
mycontrol.attributes.add("myIndex",rowNum)
}


In the code that is executed when the control is clicked:

Code:
private void userdefinedfunc(Object sender){
whatever SomeControl = (whatever) sender
// index = sender.attributes("myIndex")
}



Greetings, Harm Meijer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top