如何将数据表值绑定到gridview文本框中 [英] How to bind datatable value into gridview text box
本文介绍了如何将数据表值绑定到gridview文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我发布了一些错误的代码,所以我只是删除了我的问题。
对不起。
here i've posted some wrong code, so i just remove my question.
Sorry for this.
推荐答案
添加评估每个要与数据表中的数据绑定的文本框。
Add Eval to each of the textboxes that you want to bind with the data from datatable.
<asp:textbox id="txtBenid" enabled="false" runat="server" xmlns:asp="#unknown"></asp:textbox>
这是您希望id值为的文本框的代码绑定。
将您的代码修改为:
This is your code for the textbox in which you want id value to be binded.
Modify your code as:
<asp:textbox id="txtBenid" enabled="false" runat="server" xmlns:asp="#unknown">Text='<%# Eval("id") %>'></asp:textbox>
也适用于其他文本框。
Similary add for other textboxes too.
in for循环减少dt.Rows.Count-1
in for loop to decrease the dt.Rows.Count-1
for (int i = 0; i < dt.Rows.Count-1; i++)
{
dr = dtTemp.NewRow();
dr["id"] = dt.Rows[i][0].ToString();
dr["Benificiary"] = dt.Rows[i][1].ToString();
dr["Progress"] = string.Empty;
dr["Remarks"] = string.Empty;
dtTemp.Rows.Add(dr);
}
您必须更改上面的代码,如下所示:您必须将文本框的ID作为数据列,而不是标题文字。
You have to change the above code as below :You have to give ids of text boxes as data column,Not the header text.
dtTemp.Columns.Add(new DataColumn("txtBenid", typeof(string)));
dtTemp.Columns.Add(new DataColumn("txtBen", typeof(string)));
dtTemp.Columns.Add(new DataColumn("txtProg", typeof(string)));
dtTemp.Columns.Add(new DataColumn("txtRem", typeof(string)));
样本: http://matifnadeem.blogspot.com/2013/05/adding-dynamic-rows-in-aspnet-gridview.html [ ^ ]
我希望这会对你有所帮助。
Sample : http://matifnadeem.blogspot.com/2013/05/adding-dynamic-rows-in-aspnet-gridview.html[^]
I hope this will help to you.
这篇关于如何将数据表值绑定到gridview文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文