zoukankan      html  css  js  c++  java
  • 获取gridview模板列里面的控件的ID

    后台 

    public void bind()
        {
            string sqlstr = "select * from t1";
            DataSet myds = constring.Query(sqlstr);
            GridView2.DataSource = myds;
            GridView2.DataBind();
        }

    //翻页

        protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView2.PageIndex = e.NewPageIndex;
            bind();
        }

    //编辑 

    protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
      {
          GridView2.EditIndex = e.NewEditIndex;
          bind();
          ((TextBox)(GridView2.Rows[e.NewEditIndex].Cells[3].FindControl("txtbox1"))).Enabled = true;
          ((TextBox)(GridView2.Rows[e.NewEditIndex].Cells[4].FindControl("txtbox2"))).Enabled = true;
      }

    //更新

      protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
      {

          string sqlstr = "update tblpsworkingday set Exclusive=" + Convert.ToInt32(((TextBox)(GridView2.Rows[e.RowIndex].Cells[3].FindControl("txtbox1"))).Text.ToString().Trim()) + ",maxqty=" + Convert.ToInt32(((TextBox)(GridView2.Rows[e.RowIndex].Cells[4].FindControl("txtbox2"))).Text.ToString().Trim()) + " where id='" + GridView2.DataKeys[e.RowIndex].Value.ToString() + "'";
          int k = constring.Conn(sqlstr);
          GridView2.EditIndex = -1;
          bind();
      }

    //取消编辑
      protected void GridView2_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
      {
          GridView2.EditIndex = -1;
          bind();
      }

    //删除
      protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
      {
          string sqlstr = "delete from tblpsworkingday where id='" + GridView2.DataKeys[e.RowIndex].Value.ToString() + "'";
          int k = constring.Conn(sqlstr);
          bind();
      }

    //前台

    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CellPadding="4"
      ForeColor="#333333" GridLines="None"  OnRowEditing="GridView2_RowEditing"
      OnRowUpdating="GridView2_RowUpdating" DataKeyNames="id"  OnRowDeleting="GridView2_RowDeleting"  OnRowCancelingEdit="GridView2_RowCancelingEdit"  AllowPaging="True" PageSize="14"  OnPageIndexChanging="GridView2_PageIndexChanging">
      <FooterStyle  Font-Bold="True" ForeColor="White" />
      <Columns>

        <asp:TemplateField HeaderText="单位名称">
                            <ItemTemplate>
                            <asp:Label ID="lbldw1" runat="server" Text=' <%# meinian_site.connec.constring.CutString(Eval("tblCom_Title").ToString(),5)%>' ToolTip='<%# Eval("tblCom_Title").ToString()%>'></asp:Label>    
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="门店名称">
                            <ItemTemplate>
                            <asp:Label ID="lblmd1" runat="server" Text=' <%# meinian_site.connec.constring.CutString(Eval("point_name").ToString(),5)%>' ToolTip='<%# Eval("point_name").ToString()%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                            <asp:TemplateField HeaderText="预约日期">
                            <ItemTemplate>
                                 <%# Eval("date","{0:d}")%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="是否独占">
                            <ItemTemplate>
                            <asp:TextBox ID="txtbox1" runat="server" Text=' <%# Eval("Exclusive").ToString() %>' Width="30" Enabled="false" ></asp:TextBox>    
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="人数">
                            <ItemTemplate>
                            <asp:TextBox ID="txtbox2" runat="server" Text=' <%# Eval("maxqty").ToString() %>'  Width="30" Enabled="false" ></asp:TextBox>    
                            </ItemTemplate>
                        </asp:TemplateField>

      <asp:CommandField HeaderText="编辑" ShowEditButton="True" />
      <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />

      </Columns>
      <RowStyle BackColor="#EFF3FB"  />
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333"  />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#2461BF"  />
                <AlternatingRowStyle BackColor="White" />
      </asp:GridView>

  • 相关阅读:
    es6基础系列二:Number
    es6基础系列一:let和const
    linux常用命令
    input 事件与汉字输入法:使用compositionend事件解决
    正则表达式
    php 调试环境配置(mac)
    前端实习生:10个月的总结
    人生路:程序员、飞行员?
    科三流水账
    阻止pc端浏览器缩放js代码
  • 原文地址:https://www.cnblogs.com/xiaogelove/p/1891151.html
Copyright © 2011-2022 走看看