如何通过从Textbox输入来开始增加网格中的列(Sl.No)值? [英] How to start increment a column(Sl.No) value in grid by giving input from Textbox?

查看:74
本文介绍了如何通过从Textbox输入来开始增加网格中的列(Sl.No)值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过从文本框中提供用户输入并自动增加gridview的列(Sl.No)值来增加基于gridview中生成的行的数量?





ex:

i有10行格。我给的文本框i / p为100,SlNo列应该从100-110开始。



我得到了上述问题的答案。



现在我更新的质量保证是



从sql表中检查后计数增量是否存在于表中?如果存在跳过那个没有。



ex:

表:101,102,105,110

I / P是:100 (来自文本框)

在DataGrid中的行数是:10

我的必需O / P是100,103,104,106,107,108,109,111,112,113

解决方案

< blockquote> gridview的OnRowDataBound事件,你可以添加带有gridview行数的文本框值。



  <   asp:TemplateField     HeaderText   =  SNo >  
< ItemTemplate >
< asp:Label ID = lblSNo runat = server > < / asp:Label >
< / ItemTemplate >
< / asp:TemplateField >







  protected   void  gv_OnRowDataBound( object  sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataC ontrolRowType.DataRow)
{
((Label)e.Row.FindControl( lblSNo ))文本= Convert.ToString(Convert.ToInt32(txtsno.Text)+ Convert.ToInt32(e.Row.RowIndex + 1));
}
}


我可以告诉你绑定到datagrid的数据包含你想要的列标识符和你绑定的集合到网格是我的收藏。每当用户更改文本框的文本或推送搜索时,您必须执行此操作。



  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)。取( 10 );
}

myDatagrind.DataSource = finalData;


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

解决方案

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

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




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));
    }
} 


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.

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;


这篇关于如何通过从Textbox输入来开始增加网格中的列(Sl.No)值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆