gridview and attribute

Discussion in 'ASP .Net Web Controls' started by Al Smith, May 15, 2006.

  1. Al Smith

    Al Smith Guest

    I am trying to attach client side javascript to a check box contained within
    the gridview control using the attribute method. My aspx code is:
    <asp:TemplateField HeaderText="Set Password">
    <EditItemTemplate>
    <asp:CheckBox ID="chkSetPassword" runat="server" Checked='<%#
    Bind("SetPassword") %>' />
    </EditItemTemplate>
    <ItemTemplate>
    <asp:CheckBox ID="chkSetPassword" runat="server" Checked='<%#
    Bind("SetPassword") %>'
    Enabled="false" />
    </ItemTemplate>
    </asp:TemplateField>


    In the code behind, RowCreated() event I use the chk.Attributes to attempt
    the wiring of the onclick event to my JS:
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {

    if (e.Row.RowState == DataControlRowState.Edit) {
    CheckBox chk = (CheckBox)e.Row.FindControl("chkSetPassword");
    if (chk != null){
    chk.Attributes["onclick"] = "javascript:eek:nclickSetPassword();";
    }
    }
    }


    When I do a view source in the browser I get:
    <input id="GridView1_ctl02_chkSetPassword" type="checkbox"
    name="GridView1$ctl02$chkSetPassword" onclick="flagDataChanged(this);" />


    Is there a was to add my JS event to this?

    Thanks
    Al
    Al Smith, May 15, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kanpeter
    Replies:
    0
    Views:
    1,321
    kanpeter
    Oct 26, 2010
  2. dkmd_nielsen
    Replies:
    6
    Views:
    198
    Joel VanderWerf
    Nov 26, 2008
  3. Replies:
    4
    Views:
    129
  4. Marc Aymerich
    Replies:
    0
    Views:
    62
    Marc Aymerich
    Nov 24, 2013
  5. Devin Jeanpierre
    Replies:
    12
    Views:
    99
    Steven D'Aprano
    Nov 24, 2013
Loading...

Share This Page