当前位置:编程学习 > C#/ASP.NET >>

求助。asp.net gridview我按编辑的时候想禁用掉模版列里面textbox。怎么搞。我想在GridView1_RowEditing事件里写

          <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  Width = "1340px"
                CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" 
                onrowcancelingedit="GridView1_RowCancelingEdit" 
                onrowdatabound="GridView1_RowDataBound" 
                onselectedindexchanged="GridView1_SelectedIndexChanged" onpageindexchanging="GridView1_PageIndexChanging" 
                onrowediting="GridView1_RowEditing" 
                onrowupdating="GridView1_RowUpdating" DataKeyNames="F_AppId" 
                onrowdeleting="GridView1_RowDeleting">
                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                <RowStyle BackColor="#E3EAEB" />
                <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#7C6F57" />
                <AlternatingRowStyle BackColor="White" />
                 <Columns>
                     <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
                     <asp:TemplateField HeaderText="修改" ShowHeader="False">
                         <EditItemTemplate>
                             <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                                 CommandName="Update" Text="更新"></asp:LinkButton>
                              <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                                 CommandName="Cancel" Text="取消"></asp:LinkButton>
                         </EditItemTemplate>
                         <ItemTemplate>
                             <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                                 CommandName="Edit" Text="修改"></asp:LinkButton>
                         </ItemTemplate>
                     </asp:TemplateField>
                    <asp:BoundField DataField="F_AppId" HeaderText="流水号" ReadOnly="True" />
                    <asp:BoundField DataField="F_AppDate" HeaderText="申请日期" ReadOnly="True" />
                    <asp:BoundField DataField="F_Customer" HeaderText="客户名称" ReadOnly="True"/>
                    <asp:BoundField DataField="F_Temp" HeaderText="客户料号" ReadOnly="True" />
                    <asp:BoundField DataField="F_CapXonPN" HeaderText="制造商料号" ReadOnly="True" />
                    <asp:BoundField DataField="F_CustomerETA" HeaderText="到底客户处时间" ReadOnly="True" />
                    <asp:BoundField DataField="F_Quality" HeaderText="数量" ReadOnly="True" />
                    <asp:BoundField DataField="F_Specification" HeaderText="详细规格"  ReadOnly="True"/>
                     <asp:TemplateField HeaderText="样品单号">
                         <EditItemTemplate>
                             <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("F_SampleNo") %>'></asp:TextBox>
                         </EditItemTemplate>
                         <ItemTemplate>
                             <asp:Label ID="Label1" runat="server" Text='<%# Bind("F_SampleNo") %>'></asp:Label>
                         </ItemTemplate>
                     </asp:TemplateField>
                     <asp:TemplateField HeaderText="供应商交期回复">
                         <EditItemTemplate>
                             <asp:TextBox ID="TextBox2" runat="server" 
                                 Text='<%# Bind("F_SuppliersReplyDate") %>' onClick="WdatePicker()" class="Wdate"></asp:TextBox>
                         </EditItemTemplate>
                         <ItemTemplate>
                             <asp:Label ID="Label2" runat="server" 
                                 Text='<%# Bind("F_SuppliersReplyDate") %>'></asp:Label>
                         </ItemTemplate>
                     </asp:TemplateField>
                     <asp:TemplateField HeaderText="实际寄出日期">
                         <EditItemTemplate>
                             <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("F_SentOutDate") %>' onClick="WdatePicker()" class="Wdate"></asp:TextBox>
                         </EditItemTemplate>
                         <ItemTemplate>
                             <asp:Label ID="Label3" runat="server" Text='<%# Bind("F_SentOutDate") %>'></asp:Label>
                         </ItemTemplate>
                     </asp:TemplateField>
                     <asp:TemplateField HeaderText="到苏日期">
                         <EditItemTemplate>
                             <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("F_ArriveSZDate") %>' onClick="WdatePicker()" class="Wdate"></asp:TextBox>
                         </EditItemTemplate>
                         <ItemTemplate>
                             <asp:Label ID="Label4" runat="server" Text='<%# Bind("F_ArriveSZDate") %>'></asp:Label>
                         </ItemTemplate>
                     </asp:TemplateField>
                     <asp:TemplateField HeaderText="寄往客户日期">
                         <EditItemTemplate>
                             <asp:TextBox ID="TextBox5" runat="server" 
                                 Text='<%# Bind("F_SentToCustomerDate") %>' onClick="WdatePicker()" class="Wdate"></asp:TextBox>
                         </EditItemTemplate>
                         <ItemTemplate>
                             <asp:Label ID="Label5" runat="server" 
                                 Text='<%# Bind("F_SentToCustomerDate") %>'></asp:Label>
                         </ItemTemplate>
                     </asp:TemplateField>
                    <asp:BoundField DataField="F_Memo" HeaderText="备注" />
            </Columns>
            </asp:GridView> --------------------编程问答--------------------
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {        
        this.GridView1.EditIndex = e.NewEditIndex;

        string id = this.GridView1.DataKeys[e.NewEditIndex].Value.ToString();
        string sql = string.Format("select * from T_SampleTrack where F_AppId ='{0}'", id);
        string aa = T_STM.getSampleTrack(sql).Tables[0].Rows[0]["F_SampleNo"].ToString();
        string bb = T_STM.getSampleTrack(sql).Tables[0].Rows[0]["F_SuppliersReplyDate"].ToString();
        string cc = T_STM.getSampleTrack(sql).Tables[0].Rows[0]["F_SentOutDate"].ToString();
        string dd = T_STM.getSampleTrack(sql).Tables[0].Rows[0]["F_ArriveSZDate"].ToString();
        string ee = T_STM.getSampleTrack(sql).Tables[0].Rows[0]["F_SentToCustomerDate"].ToString();

        if (aa != "" && bb != "" && cc != "" && dd != "" && ee != "")
        {
            //((BoundField)GridView1.Columns[10]).ReadOnly = true;
            //((BoundField)GridView1.Columns[11]).ReadOnly = true;
            //((BoundField)GridView1.Columns[12]).ReadOnly = true;
            //((BoundField)GridView1.Columns[13]).ReadOnly = true;
            //((BoundField)GridView1.Columns[14]).ReadOnly = true;
            //((BoundField)GridView1.Columns[1]).ReadOnly = true;
            //(GridView1.FindControl("Label1")).Visible = false;
            //GridView1.FindControl("TextBox1").Controls[0].Visible = false;
            //(GridView1.Columns[10]).Visible = false;
            //(GridView1.Columns[11]).Visible = false;
            //(GridView1.Columns[12]).Visible = false;
            //(GridView1.Columns[13]).Visible = false;
            //(GridView1.Columns[14]).Visible = false;

            ((TextBox)GridView1.Rows[e.NewEditIndex].Cells[0].Controls[10].FindControl("TextBox1")).ReadOnly = true;

            //((BoundField)GridView1.Columns[10]).ReadOnly = false;
            //((BoundField)GridView1.Columns[11]).ReadOnly = false;
            //((BoundField)GridView1.Columns[12]).ReadOnly = false;
            //((BoundField)GridView1.Columns[13]).ReadOnly = false;
            //((BoundField)GridView1.Columns[14]).ReadOnly = false;
        }
        else 
        {
            //TextBox tb1 = (TextBox)sender;
            //((BoundField)GridView1.Columns[10]).ReadOnly = false;
            //((BoundField)GridView1.Columns[11]).ReadOnly = false;
            //((BoundField)GridView1.Columns[12]).ReadOnly = false;
            //((BoundField)GridView1.Columns[13]).ReadOnly = false;
            //((BoundField)GridView1.Columns[14]).ReadOnly = false;
            //((BoundField)GridView1.Columns[1]).ReadOnly = false;
            //(FindControl("TextBox1")).Visible = true;
            //GridView1.FindControl(tb1).Controls[0].Visible = true;
            //((TextBox)GridView1.Rows[e.NewEditIndex].FindControl("TextBox1")).Visible = true;
            (GridView1.Columns[10]).Visible = true;
            (GridView1.Columns[11]).Visible = true;
            (GridView1.Columns[12]).Visible = true;
            (GridView1.Columns[13]).Visible = true;
            (GridView1.Columns[14]).Visible = true;
            //((BoundField)GridView1.Columns[10]).ReadOnly = true;
            //((BoundField)GridView1.Columns[11]).ReadOnly = true;
            //((BoundField)GridView1.Columns[12]).ReadOnly = true;
            //((BoundField)GridView1.Columns[13]).ReadOnly = true;
            //((BoundField)GridView1.Columns[14]).ReadOnly = true;
        }
        bind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        
        bind();
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        
        string id = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
        string sql = string.Format("select * from T_SampleTrack where F_AppId ='{0}'", id);
        string aa = T_STM.getSampleTrack(sql).Tables[0].Rows[0]["F_SampleNo"].ToString();
        string bb = T_STM.getSampleTrack(sql).Tables[0].Rows[0]["F_SuppliersReplyDate"].ToString();
        string cc = T_STM.getSampleTrack(sql).Tables[0].Rows[0]["F_SentOutDate"].ToString();
        string dd = T_STM.getSampleTrack(sql).Tables[0].Rows[0]["F_ArriveSZDate"].ToString();
        string ee = T_STM.getSampleTrack(sql).Tables[0].Rows[0]["F_SentToCustomerDate"].ToString();
        if (aa != "" && bb != "" && cc != "" && dd != "" && ee != "")
        {

            string mm = ((TextBox)(this.GridView1.Rows[e.RowIndex].Cells[15].Controls[0])).Text.ToString();
            string sql1 = string.Format("update T_SampleTrack set F_Memo='{0}'where F_AppId='{1}'", mm, id);
            T_STM.updateT_SampleTrack(sql1);
            Response.Write("<script language=javascript>alert('更新备注成功!');</script>");
        }
        else
        {
            string ii = ((TextBox)(this.GridView1.Rows[e.RowIndex].Cells[10].Controls[1])).Text.ToString();
            if (ii == "")
            {
                Response.Write("<script language=javascript>alert('样品单号不能为空!');</script>");
                return;
            }
            string jj = ((TextBox)(this.GridView1.Rows[e.RowIndex].Cells[11].Controls[1])).Text.ToString();
            if (jj == "")
            {
                Response.Write("<script language=javascript>alert('供应商交期回复不能为空!');</script>");
                return;
            }
            string kk = ((TextBox)(this.GridView1.Rows[e.RowIndex].Cells[12].Controls[1])).Text.ToString();
            if (kk == "")
            {
                Response.Write("<script language=javascript>alert('实际寄出日期不能为空!');</script>");
                return;
            }
            string ll = ((TextBox)(this.GridView1.Rows[e.RowIndex].Cells[13].Controls[1])).Text.ToString();
            if (ll == "")
            {
                Response.Write("<script language=javascript>alert('到苏州日期不能为空!');</script>");
                return;
            }
            string nn = ((TextBox)(this.GridView1.Rows[e.RowIndex].Cells[14].Controls[1])).Text.ToString();
            if (nn == "")
            {
                Response.Write("<script language=javascript>alert('寄往客户日期不能为空!');</script>");
                return;
            }
            string mm = ((TextBox)(this.GridView1.Rows[e.RowIndex].Cells[15].Controls[0])).Text.ToString();
            string sql2 = string.Format("update T_SampleTrack set F_SampleNo='{0}',F_SuppliersReplyDate='{1}',F_SentOutDate='{2}',F_ArriveSZDate='{3}',F_SentToCustomerDate='{4}',F_Memo='{5}'where F_AppId='{6}'",  ii, jj, kk, ll, nn, mm, id);
            T_STM.updateT_SampleTrack(sql2);
            Response.Write("<script language=javascript>alert('更新成功!');</script>");

        }
        //string sql = string.Format("update T_SampleTrack set F_AppId='{0}', F_AppDate='{1}',F_Customer='{2}',F_Temp='{3}',F_CapXonPN='{4}',F_CustomerETA='{5}',F_Quality='{6}',F_Specification='{7}',F_SampleNo='{8}',F_SuppliersReplyDate='{9}',F_SentOutDate='{10}',F_ArriveSZDate='{11}',F_SentToCustomerDate='{12}',F_Memo='{13}'where F_AppId='{14}'", F_AppId, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, ll, nn, mm, F_AppId);
        //T_STM.updateT_SampleTrack(sql);
        //Response.Write("<script language=javascript>alert('更新成功!');</script>");
        this.GridView1.EditIndex = -1;
        bind();

    }
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,