Row number in gridview using linq [Solved]
-
hi, im thinking about make row numbers in datagridview using linq extentions but i dont know how, currently i use {for statement} to make row numbers, when data in grid grow up to 10000 records then its really slow and its my problem , i just wanna make it quicker. ty
-
hi, im thinking about make row numbers in datagridview using linq extentions but i dont know how, currently i use {for statement} to make row numbers, when data in grid grow up to 10000 records then its really slow and its my problem , i just wanna make it quicker. ty
What do you mean row numbers? You want to a row number to the display? Is this Windows or web? Perhaps if you showed a little of the code we could make suggestions for improvement
I know the language. I've read a book. - _Madmatt
-
What do you mean row numbers? You want to a row number to the display? Is this Windows or web? Perhaps if you showed a little of the code we could make suggestions for improvement
I know the language. I've read a book. - _Madmatt
thanks for ur answer. this is the current code
for(int i=0;i < dg.RowCount;i++) { dg.Rows[i].Cells[0].Value= i.ToString(); }
-
hi, im thinking about make row numbers in datagridview using linq extentions but i dont know how, currently i use {for statement} to make row numbers, when data in grid grow up to 10000 records then its really slow and its my problem , i just wanna make it quicker. ty
You can simply use the GridView Property.
asp:TemplateField
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>I don't feel that linq is really needed here. But still if wish to do it using linq, use project and add rowNumber in your datasource.
Anurag Gandhi.
http://www.gandhisoft.com
Life is a computer program and every one is the programmer of his own life. -
You can simply use the GridView Property.
asp:TemplateField
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>I don't feel that linq is really needed here. But still if wish to do it using linq, use project and add rowNumber in your datasource.
Anurag Gandhi.
http://www.gandhisoft.com
Life is a computer program and every one is the programmer of his own life.This shouldn't be at LINQ message board! :omg: if your paging is 10, maybe you can use
<ItemTemplate>
<%#String.Format("{0:000}", (((GridViewRow)Container).RowIndex + 1) + (GV_Resumen.PageIndex * 10))%>
</ItemTemplate>
<ItemStyle Width="2%" /> -
This shouldn't be at LINQ message board! :omg: if your paging is 10, maybe you can use
<ItemTemplate>
<%#String.Format("{0:000}", (((GridViewRow)Container).RowIndex + 1) + (GV_Resumen.PageIndex * 10))%>
</ItemTemplate>
<ItemStyle Width="2%" />OOOPs! in windows application case there is no template item and so, guys im looking for row numbering in win app using linq extention. ty
-
OOOPs! in windows application case there is no template item and so, guys im looking for row numbering in win app using linq extention. ty
try adding a superficial column! but with a dataTable...
var s = from N in Cnn.Datos.COM_TBL_Noticias
select N;
DataTable dt = new DataTable();
int i = 0;
dt.Columns.Add("Num", System.Type.GetType("System.Int32"));
dt.Columns.Add("EncabezadoNoticia", System.Type.GetType("System.String"));
dt.Columns.Add("DescripcionNoticia", System.Type.GetType("System.String"));
dt.Columns.Add("FechaNoticia", System.Type.GetType("System.DateTime"));
foreach (var lista in s)
{
dt.Rows.Add(i, lista.EncabezadoNoticia, lista.DescripcionNoticia, lista.FechaNoticia);
i++;
}
DGV_Datos.DataSource = dt;and num would be the based 0 num! xD :-D
-
try adding a superficial column! but with a dataTable...
var s = from N in Cnn.Datos.COM_TBL_Noticias
select N;
DataTable dt = new DataTable();
int i = 0;
dt.Columns.Add("Num", System.Type.GetType("System.Int32"));
dt.Columns.Add("EncabezadoNoticia", System.Type.GetType("System.String"));
dt.Columns.Add("DescripcionNoticia", System.Type.GetType("System.String"));
dt.Columns.Add("FechaNoticia", System.Type.GetType("System.DateTime"));
foreach (var lista in s)
{
dt.Rows.Add(i, lista.EncabezadoNoticia, lista.DescripcionNoticia, lista.FechaNoticia);
i++;
}
DGV_Datos.DataSource = dt;and num would be the based 0 num! xD :-D
thank you! is there any way to put numbers directly in grid or table column? foreach has a long delay!