我有一个.NET窗体应用程序一个gridview,并在回发,我没有看到在GridView中的文本框中输入的值。
I have a gridview on a .NET forms application, and on postback, I am not seeing the values entered in the textbox within a gridview.
ASPX:
<asp:GridView ID="gvItems" runat="server" AutoGenerateColumns="false" ShowHeader="false" DataKeyNames="ItemId" EnableViewState="true">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtItem" runat="server" Text="0" EnableViewState="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ItemId" />
</Columns>
</asp:GridView>
<asp:Button runat="server" ID="btn" Text="Submit" OnClick="btn_OnClick" OnClientClick="javascript:return someClientStuff();" />
code背后:
Code Behind:
protected void btn_OnClick(object sender, System.EventArgs e)
{
foreach(GridViewRow row in gvItems.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
var itemId = Convert.ToInt32(gvItems.DataKeys[row.RowIndex].Values[0]);
var itemValue = ((row.Cells[0].FindControl("txtItem") as TextBox).Text;
}
}
我看到的itemId填充的每一行,但itemValue始终是空字符串。
I am seeing itemId populated for each row, but itemValue is always empty string.
已经有一段时间,我曾在一个窗体应用程序,任何帮助是AP preciated!
Been a while since I worked on a forms application, any help is appreciated!
我会假设的DataBind
的 GridView控件的
不是如果(!的IsPostBack)
。这种添加到的Page_Load
I will assume that the DataBind
of the GridView
is not in if(!IsPostBack)
. Add this to the Page_Load
if(!IsPostBack)
{
gvItems.DataSource = soruceOftheGrid
gvItems.DataBind();
}
上一篇:BluetoothServerSocket不接受来自()返回不接受、BluetoothServerSocket
下一篇:在 Jersey 中使用 StreamingOutput 作为响应实体的示例示例、实体、Jersey、StreamingOutput