专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

急gridview取模板列textbox的值为空,该怎么处理

发布时间:2011-06-23 16:01:47 文章来源:www.iduyao.cn 采编人员:星星草
急!!gridview取模板列textbox的值为空
页面上有个gridview和一个按钮,gridview的模板列加了个textbox,为什么当我输入数据后,点击按钮后,取出textbox的值怎么老是为空?代码:
txtOnePrice = CType(GridView1.Rows(1).Cells(8).FindControl("txtOnePrice"), TextBox) 
if txtOnePrice is nothing then  
xx = txtOnePrice.Text
ShowMessage(Me, xx)
end if

------解决方案--------------------
页面加
EnableViewState="true"

下面是完整的测试例子,你直接拷贝粘贴就能看到效果了

HTML code
<%@ Page Language="VB" EnableViewState="true" AutoEventWireup="false" CodeFile="Default11.aspx.vb" Inherits="Default11" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
    <Columns>
      <asp:TemplateField HeaderText="输入">
        <ItemTemplate>
          <asp:TextBox ID="txtOnePrice" runat="server"></asp:TextBox>
        </ItemTemplate>
      </asp:TemplateField>
    </Columns>
  </asp:GridView>
  <asp:Button ID="Button1" runat="server" Text="绑定" />
  <asp:Button ID="Button2" runat="server" Text="得到输入值" />
  </form>
</body>
</html>
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: