Note that there are some explanatory texts on larger screens.

plurals
  1. POasp:GridView - change checkbox status when click anywhere in the line
    primarykey
    data
    text
    <p>I have a web app and use gridview to show some SQL data. In the GV I have a checkbox in the first column. As suggested in the title, I want to check the checkbox when user clicks anywhere in that line. How can I accomplish that. Thanks.</p> <p>This is my GV;</p> <pre><code>&lt;asp:GridView ID="myGV" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" OnRowDataBound="myGV_OnRowDataBound"&gt; &lt;Columns&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="myCB" runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" /&gt; </code></pre> <p>I use this code to highlight the row when mouse pointer is over it;</p> <pre><code>protected void myGV_OnRowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#D9ECFB'"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;"); } } </code></pre> <p>EDIT:</p> <p>I added "OnSelectedIndexChanging" and "OnSelectedIndexChanged" to the GridView and then tried this (as suggested by Ravi), but couldn't get it to work. </p> <pre><code>protected void myGV_SelectedIndexChanging(Object sender, GridViewSelectEventArgs e) { GridViewRow row = myGV.Rows[e.NewSelectedIndex]; CheckBox chk = (CheckBox)myGV.FindControl("cbIzpis"); if (chk.Checked == true) { chk.Checked = false; } else if (chk.Checked == false) { chk.Checked = true; } } protected void myGV_SelectedIndexChanged(Object sender, EventArgs e) { GridViewRow row = nyGV.SelectedRow; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload