Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to start increment a column(Sl.No) value of gridview by giving user input from Textbox & auto Increment it based on no of Rows generated in gridview?


ex:
i have 10 rows in grid. i'm giving Textbox i/p of 100 means, the SlNo column should start from 100- 110.

I got answer for above Question.

Now My updated QA is

increment that count after checking from sql table if it is exists in table? if exists skip that no .

ex:
In table : 101,102,105,110
I/P is: 100 (from textbox)
No Of Row In DataGrid is :10
my Required O/P is 100,103,104,106,107,108,109,111,112,113
Posted
Updated 6-Oct-15 4:08am
v2

OnRowDataBound event of gridview you can add textbox value with gridview row count.

ASP.NET
<asp:TemplateField HeaderText="SNo">
    <ItemTemplate>
        <asp:Label ID="lblSNo" runat="server"></asp:Label>
    </ItemTemplate>
</asp:TemplateField>



C#
protected void gv_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType==DataControlRowType.DataRow)
    {
         ((Label)e.Row.FindControl("lblSNo")).Text=Convert.ToString(Convert.ToInt32(txtsno.Text)+Convert.ToInt32(e.Row.RowIndex+1));
    }
} 
 
Share this answer
 
v3
Comments
Sathish km 6-Oct-15 8:43am    
Thks! i also got my own...
Naveen.Sanagasetti 6-Oct-15 8:51am    
Good to hear ;)
As i can tell the data you bind to the datagrid contain the column identifier you want and the collection you bind to grid is mycollection. Whenever user changes the text of the textbox or pushes search you must do this.

C#
string userInputtxt = txbUserInput.Text();
int userInputInt = 0;
var finalData = null;
if(int.TryParse(userInputtxt , out userInputInt ))
{
  finalData =  mycollection.Where(w => w.SINo >= userInputInt).Take(10).OrderBy(o => o.SINo);
}
else
{
   finalData = mycollection.OrderBy(o => o.SINo).Take(10);
}

  myDatagrind.DataSource = finalData;
 
Share this answer
 
v3
Comments
Sathish km 6-Oct-15 8:44am    
thks I also Got my own.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900