I Am Displaying Data In Datagrid And I Want To Display Serial No. For Each Row.it Should Be Autogerated.
Pls Help.
It's Really Urgent.
hi aspamit,
we have to make use of the event OnItemDataBound to create a sno or autogenerate nos.
it includes the following steps:
step1: create a template column in the datagrid control
<asp: TemplateColumn HeaderText= "sno" ......
step2: For OnItemDataBound assign an event name that would fire when an item is databound to the datagrid
<asp: DataGrid id="Datagrid1" OnItemDataBound = "populatesno"....
step3: Write the code which would create the sno within the procedure populate sno
void populatesno(object sender,DataBindItemEventArgs e)
{
(assuming the sno is in 0 location)
if e.item.itemindex <> -1 then
e.item.cells(0).text = e.item.itemindex
( or
e.item.cells(0).text= e.item.datasetindex +1)
end if
hope this will solve your purpose.
good luck.