2014-02-26 64 views
0

我正在顯示一個Gridview,其中顯示了一個帶有複選框的問題列表,用於通過或失敗。我想要做的是,當他們勾選複選框失敗時,文本框出現在下一列中,以說明原因。我Gridview的代碼如下在我的GridView中顯示可編輯的文本框

<asp:GridView ID="QuestionsGrid" runat="server" AutoGenerateColumns="False" 
     BorderStyle="None" class="gridView" 
        GridLines="None" ShowFooter="True" TotalRows="0" 
        Width="950px" CellPadding="5" CssClass="gridView" 
        EmptyDataText="No rows found." 
        style="margin-left: auto; margin-right: auto;" 
        OnRowDataBound="QuestionsGrid_RowDataBound" IgnoreFlagIdpsc="" 
        OnRowEditing="QuestionsGrid_RowEditing" onRowCommand="QuestionsGrid_RowCommand" > 
     <Columns> 
      <asp:BoundField ItemStyle-HorizontalAlign="Left" > 
        <ItemStyle HorizontalAlign="Left" Width="200px"></ItemStyle> 
      </asp:BoundField> 
      <asp:BoundField ItemStyle-HorizontalAlign="Left" > 
        <ItemStyle HorizontalAlign="Left" Width="500px"></ItemStyle> 
      </asp:BoundField>     
      <asp:TemplateField HeaderText="Passed" > 
       <ItemTemplate> 
        <asp:CheckBox ID="CheckBox1" runat="server" Checked="true" ></asp:CheckBox> 
       </ItemTemplate>     
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="Value" > 
       <ItemTemplate> 
        <asp:TextBox ID="TextBox1" runat="server" Width="100px" Font-Size="10pt"></asp:TextBox> 
       </ItemTemplate>     
      </asp:TemplateField> 
     </Columns> 
    </asp:GridView> 

我已經嘗試設置事件onCheckChanged與我的複選框不起作用。我想這樣做,而不使用我的GridView的可編輯按鈕。

+0

你onCheckChanged – donstack

回答

0

下面的代碼應該工作:

protected void CheckBox1_CheckedChanged(object sender, EventArgs e) 
{ 
    var checkbox = sender as CheckBox; 

    //version 1: show the text box on click 
    checkbox.Parent.FindControl("TextBox1").Visible = true; 

    //version 1: show the text box based on checkbox state 
    checkbox.Parent.FindControl("TextBox1").Visible = checkbox.Checked; 
} 

不要忘記從ASPX標記與

<asp:TemplateField HeaderText="Passed"> 
    <ItemTemplate> 
     <asp:CheckBox ID="CheckBox1" runat="server" Checked="true" OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="true"></asp:CheckBox> 
    </ItemTemplate> 
</asp:TemplateField> 
+0

這偉大的工程做了什麼添加處理程序(和自動回)謝謝 – user616076