checkbox inside gridview

  • Thread starter Thread starter E. Kwong
  • Start date Start date
E

E. Kwong

I'm trying to make visible or invisible a textbox depending on whether a
checkbox is clicked. Both controls are inside the same gridview. I've
tried program this in the CheckedChanged event but visual studio keeps
telling me the textbox control is not declared. Here's how the controls are
in gridview:

<edititemtemplate>
<asp:CheckBox checked='<%#Eval("chkfield")%>'
ID="chk1" runat="server" TextAlign="Left" AutoPostBack="true"
OnCheckedChanged="chk1_CheckedChanged" />
<asp:TextBox id="txt1" Text='<%#Eval("textfield") %>'
Width="30" MaxLength="1" runat="server" />
</edititemtemplate>

What should be the correct way of doing this? Does this has to be done in
one of those row-level event of the gridview? Appreciate any advice.
 
Since the Checked property is databound, you need to run your code in the
RowDataBound event. The event is raised for every row, so you need to detect
the event raised for the row that is edited.
 
Back
Top