<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3" ShowFooter="false"
                                            BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" Font-Size="12px"  Width="760px" GridLines="Vertical" OnRowDataBound="GridView1_RowDataBound">
                                            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />                         
                                 <Columns>               
                                 <asp:TemplateField  HeaderText="选择">
                                 <HeaderStyle HorizontalAlign="Center" Width="30px" />
                                 <ItemStyle HorizontalAlign="Center" Width="30px" />
                                 <ItemTemplate>
                                     <asp:CheckBox ID="ChkSel" runat="server"/>
                                 </ItemTemplate>
                                 </asp:TemplateField>                                 
                                <asp:TemplateField HeaderText="序号" InsertVisible="False">
                                  <ItemStyle HorizontalAlign="Center"  Width="30px" />
                                  <HeaderStyle HorizontalAlign="Center" Width="30px" />
                                 <ItemTemplate>
                                     <asp:Label ID="LblNum" runat="server" Text='<%# this.GridView1.PageIndex * this.GridView1.PageSize + this.GridView1.Rows.Count + 1%>'/>
                                </ItemTemplate>
                                </asp:TemplateField>                                      
                             <asp:TemplateField HeaderText="拆分数量" InsertVisible="False">
                              <ItemStyle HorizontalAlign="Right" Width="60px"/>
                              <HeaderStyle HorizontalAlign="Center" Width="60px" />
                             <ItemTemplate>
                                 <asp:TextBox id="TxtSL" runat="server" Width="60px" MaxLength="10" onKeyPress="check(this)" Text='<%# DataBinder.Eval(Container.DataItem,"分车数量","{0:#.##}") %>'>
</asp:TextBox>
                            </ItemTemplate>
                            </asp:TemplateField> 
                             
                                                  
                            </Columns>
                            <RowStyle ForeColor="Black" BackColor="#EEEEEE" />
                            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                            <AlternatingRowStyle BackColor="Gainsboro" />
            </asp:GridView>  
点击 CheckBox  为选中状态时 TextBox  可以输入或enable为true 
点击 CheckBox  为没有选中状态时 TextBox  可以输入或enable为false应该如何实现?

解决方案 »

  1.   


     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                CheckBox ChkBox = (CheckBox)e.Row.Cells[x].FindControl("yourCheckBox");
                TextBox TxtBox = (TextBox)e.Row.Cells[x].FindControl("yourTextBox");
                if (ChkBox.Checked == true)
                {
                    TxtBox.Enabled = true;
                }
                else
                {
                    TxtBox.Enabled = false;
                }
            }
        }
      

  2.   

    <asp:CheckBox ID="ChkSel" runat="server" onclick='document.getElementById(this.id.replace("_ChkSel", "_TxtSL").disabled = !this.checked'/>