我在ASP.NET页面上有一个GridView,其TemplateField列在ItemTemplate中有一个TextBox。然后我有一个命令字段,它应该从该TextBox中提取文本,并在运行存储过程的SqlCommand中使用它。无法从gridview上的文本框中获取值
这里是我的C#代码:
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = this.gvwSNConfirm.Rows[index];
TableCell intID = selectedRow.Cells[1];
int reqID = int.Parse(intID.Text);
// Get the SN from the text box on the selected row
TableCell snCell = selectedRow.Cells[0];
TextBox tbox = (TextBox)staffNum.FindControl("txtSN");
string stSN = tbox.Text.ToString();
当我添加一个破发点,看我得到正确的ID但TBOX的文字是“为INTID和tbox.Text值”。
的加价为两列,我引用是
<asp:TemplateField HeaderText="SN">
<ItemTemplate>
<asp:TextBox ID="txtSN" runat="server" MaxLength="20" Width="100px" />
</ItemTemplate>
<HeaderStyle BackColor="#171695" Font-Names="Arial" Font-Size="Small" ForeColor="White" Wrap="true" />
</asp:TemplateField>
<asp:BoundField DataField="Request" HeaderText="Request" ReadOnly="true" SortExpression="Request" />
任何人都可以提供任何帮助,为什么我不能得到从文本框中的文本?它第一次运行,但后来所有的tbox文本值已经“”。
非常感谢
安迪
NEW CODE(05/03/2010):
protected void gvwSecond_RowCommand(object sender, GridViewCommandEventArgs e)
{
if ((e.CommandName == "Confirm") || (e.CommandName == "Decline"))
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvwSecond.Rows[index];
int secondID = int.Parse(row.Cells[1].Text);
TextBox txtsn = ((TextBox)row.FindControl("txtSecSN"));
string sn = txtsn.Text;
设法让代码工作后,它突然停止工作,我不知道为什么。上面包含了正在工作的更新代码。 – anD666