checkbox inside gridview

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • E. Kwong

    checkbox inside gridview

    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:

    <edititemtempla te>
    <asp:CheckBox checked='<%#Eva l("chkfield")%> '
    ID="chk1" runat="server" TextAlign="Left " AutoPostBack="t rue"
    OnCheckedChange d="chk1_Checked Changed" />
    <asp:TextBox id="txt1" Text='<%#Eval(" textfield") %>'
    Width="30" MaxLength="1" runat="server" />
    </edititemtemplat e>

    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.


  • Eliyahu Goldin

    #2
    Re: checkbox inside gridview

    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.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]



    "E. Kwong" <ekwong999AThot mail.comwrote in message
    news:e6VF2dRSJH A.4772@TK2MSFTN GP06.phx.gbl...
    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:
    >
    <edititemtempla te>
    <asp:CheckBox checked='<%#Eva l("chkfield")%> '
    ID="chk1" runat="server" TextAlign="Left " AutoPostBack="t rue"
    OnCheckedChange d="chk1_Checked Changed" />
    <asp:TextBox id="txt1" Text='<%#Eval(" textfield")
    %>' Width="30" MaxLength="1" runat="server" />
    </edititemtemplat e>
    >
    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.
    >
    >

    Comment

    Working...