checkbox inside gridview

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.
 
E

Eliyahu Goldin

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top