autogenerate column in datagridview in vb.net 2005
-
Sir/Madam, I have a table , having two fields , first for name and second for roll number.I don't have serial number field in that table.Can , I display Serial number field in the datagridview , with those two fields. I mean if i have ten records in the table. Then datagrid should display record no for each row, like for first row it should display 1 , and for second row , there should display 2 and so on.This should happen in the extra column in the datagridview.Is it possible. Please help. Thanks and regards Pankaj
-
Sir/Madam, I have a table , having two fields , first for name and second for roll number.I don't have serial number field in that table.Can , I display Serial number field in the datagridview , with those two fields. I mean if i have ten records in the table. Then datagrid should display record no for each row, like for first row it should display 1 , and for second row , there should display 2 and so on.This should happen in the extra column in the datagridview.Is it possible. Please help. Thanks and regards Pankaj
Hi, You can use sql query in this case. If your current sql query is - select name,rollno from students Then modify the query as - select 0 as [Serial No.],name, rollno from students. This modified query will generate a column named Serial No. whoes rows will be filled by 0. Then in the program use a counter to count the rows, in the RowDataBound event handler. Replace the text in column 0 with the counter value. You will get your desired resutls. Hope i am clear enough. I am assuming that you are using SQL Server as database.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder