Please help me.. how can i set ID to tabelrows generated by datagrid/datalist.. i mean.. i want to assign a row id by myself to every row of datalist
+1
A:
Attach a handler for the ItemDataBound
event on your control:
<asp:DataGrid OnItemDataBound="myGrid_ItemDataBound" ...>
Declare the handler method like this:
protected void myGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
e.Item.Attributes.Add("id", "some_id");
}
Jørn Schou-Rode
2010-03-31 10:02:34
thanks dear, but its not working...
Rajesh Rolen- DotNet Developer
2010-03-31 10:09:48
i have used like this : Protected Sub dljyotishpaid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dljyotishpaid.ItemDataBound If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then e.Item.Attributes.Add("id", "1") End If End Sub
Rajesh Rolen- DotNet Developer
2010-03-31 10:10:30
@Raj: The C# version works fine here, and your VB translation looks fine to me. What problem are you facing? Any compile error or runtime exception?
Jørn Schou-Rode
2010-03-31 10:18:22
no error or exception but when i see the viewsource of page its not showing me id their for TR
Rajesh Rolen- DotNet Developer
2010-03-31 10:24:32
showing like this : <table id="ctl00_CPH1_dljyotishpaid" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;"> <tr> <td valign="top">
Rajesh Rolen- DotNet Developer
2010-03-31 10:25:25
Did you remember to attach the event handler (first code sample in my answer)? If yes: try explicitly throwing an exception from the handler method to see if the method is ever invoked.
Jørn Schou-Rode
2010-03-31 10:31:43
i have debugged... my debugger is going through these lines.. but i don't know why its not working
Rajesh Rolen- DotNet Developer
2010-03-31 10:50:35
Does the debugger hit `e.Item.Attributes.Add("id", "1")` once for each row?
Jørn Schou-Rode
2010-03-31 10:58:28