| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 756 人关注过本帖
标题:为什么获取不到模板列TextBox1的值?
只看楼主 加入收藏
aei135
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:12
帖 子:232
专家分:1176
注 册:2009-4-6
结帖率:100%
收藏
 问题点数:0 回复次数:1 
为什么获取不到模板列TextBox1的值?
<%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="ClassMaintain.WebForm3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
        <title>WebForm3</title>
        <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
        <meta content="C#" name="CODE_LANGUAGE">
        <meta content="JavaScript" name="vs_defaultClientScript">
        <meta content="http://schemas. name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <div><FONT face="宋体"></FONT><FONT face="宋体"></FONT><br>
                <br>
            </div>
            <div>
                <asp:datagrid id="dg1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server"
                    AutoGenerateColumns="False" DataKeyField="a" Font-Size="X-Small" BorderColor="#3366CC" BorderStyle="None"
                    BorderWidth="1px" BackColor="White" CellPadding="4" Width="100%">
                    <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
                    <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
                    <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
                    <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
                    <Columns>
                        <asp:BoundColumn DataField="a" HeaderText="分类1"></asp:BoundColumn>
                        <asp:TemplateColumn HeaderText="分类2">
                            <ItemTemplate>
                                <asp:Label id="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"b")%>'>Label</asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox id="TextBox1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"b")%>'>
                                </asp:TextBox>
                            </EditItemTemplate>
                        </asp:TemplateColumn>
                        <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" HeaderText="编辑" CancelText="取消" EditText="编辑"></asp:EditCommandColumn>
                        <asp:TemplateColumn HeaderText="新增">
                            <ItemTemplate>
                                <asp:Button id="add" runat="server" Text="新增"></asp:Button>
                            </ItemTemplate>
                        </asp:TemplateColumn>
                        <asp:ButtonColumn Text="删除" HeaderText="删除" CommandName="Delete"></asp:ButtonColumn>
                    </Columns>
                    <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
                </asp:datagrid>
            </div>
        </form>
    </body>
</HTML>




private void dg1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            string t=((TextBox)e.Item.FindControl("TextBox1")).Text.Trim();
           string str="update test set b='"+t+"' where a='"+dg1.DataKeys[e.Item.ItemIndex].ToString()+"'";
            SqlConnection con=new SqlConnection(ConfigurationSettings.AppSettings["con"]);
            SqlCommand cmd=new SqlCommand(str,con);
            con.Open();
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch(Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
            dg1.EditItemIndex=-1;
            Db();
            Response.Write("<script>alert('"+t+"'+'"+dg1.DataKeys[e.Item.ItemIndex].ToString()+"');</script>");
        }
为什么在编辑操作后,在TextBox1中输入值进行更新却没反应,无法抓到输入到TextBox1中的数值,请高手帮忙解决,谢谢!
搜索更多相关主题的帖子: 模板 获取 
2010-05-12 11:37
aei135
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:12
帖 子:232
专家分:1176
注 册:2009-4-6
收藏
得分:0 
已解决,没有用IsPostBack的原因
2010-05-12 12:03
快速回复:为什么获取不到模板列TextBox1的值?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018792 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved