从文本框值填充网格视图. [英] fill grid view from textbox values..
本文介绍了从文本框值填充网格视图.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是lakshmana rao,我的页面上有3个文本框和1个提交按钮,当我单击提交"按钮时,在文本框中输入的值将显示在网格视图中,而无需使用任何ado概念就像数据集和数据表等.,
通过直接将文本框中的值出价到gridview.
请任何人给我建议解决方案...
谢谢...
HI i am lakshmana rao, I have 3 text boxes and 1submit button in my page, when i click the submit button the values entered in the text boxes are displayed in the grid view,this is done with out using any ado concepts just like dataset& data table etc..,
By directly the values in the textboxes are bid to the gridview.
Please any one suggest me the solution...
thanking you...
推荐答案
GridView需要绑定到某种类型的数据源;数据表,列表或任何可枚举的对象.从文本框中获取值,将其放置在列表中并绑定到gridview.
The GridView needs to be bound to some type of datasource; a datatable, list, or any enumerable object. Take the values from the textboxes, place them in a list and bind to the gridview.
试试这个
Hi ,
try this
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
if (GridView2.Rows.Count == 0)
{
dt = MakeTable();
}
else
{
dt =(DataTable) ViewState["dt"];
}
DataRow dr = dt.NewRow();
dr[0] = TextBox2.Text;
dr[1] = TextBox3.Text;
dr[2] = TextBox4.Text;
dt.Rows.Add(dr);
GridView2.DataSource = null;
GridView2.DataSource = dt;
GridView2.DataBind();
ViewState.Add("dt", dt);
}
DataTable MakeTable()
{
DataTable Mydt = new DataTable();
DataColumn col1 = new DataColumn("col");
col1.DataType = System.Type.GetType("System.String");
Mydt.Columns.Add(col1);
DataColumn col2 = new DataColumn("col2");
col1.DataType = System.Type.GetType("System.String");
Mydt.Columns.Add(col2);
DataColumn col3 = new DataColumn("col3");
col1.DataType = System.Type.GetType("System.String");
Mydt.Columns.Add(col3);
return Mydt;
}
或
OR
protected void Button2_Click(object sender, EventArgs e)
{
string[] xx = new string[3];
xx[0] = TextBox2.Text;
xx[1] = TextBox3.Text;
xx[2] = TextBox4.Text;
GridView2.DataSource= xx.ToList();
GridView2.DataBind();
}
<div>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
最好的问候
米特瓦里(M.Mitwalli)
Best Regards
M.Mitwalli
这篇关于从文本框值填充网格视图.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文