Click here to Skip to main content
12,945,800 members (53,649 online)
Rate this:
Please Sign up or sign in to vote.
Hi everybody,

My GridView is look like this..

col1    col2     col3 
1        A        1.2
2        B        3.4
         C        2.3
3        A        2

Here col1 is PK column now i'm doing checkBox selection for each and every row of gridview.

function CheckAll(oCheckbox) 
    var gdDocument = document.getElementById("<%=gdDocument.ClientID %>");
    for (i = 1; i < gdDocument.rows.length; i++) {
               gdDocument.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked;

code behind:

             <input id="chkSelect" type="checkbox" onclick="CheckAll(this)"                runat="server" />
           <asp:CheckBox ID="chkSelect" runat="server" />

this code for gridview all rows selection. But i want based upon PK column i want to display the checkBox.


in row 3 there is no record for col1. so, i don't want to display checkbox in that row .

How to do this can any one help me...
Posted 29-Jan-13 1:15am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

After Binding the grid to that data u cn use following code to achieve ur task

for (int i = 0; i < GridView1.Rows.Count; i++)
           if (GridView1.Rows[i].Cells[0].Text == string.Empty)
               CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
               chk.Visible = false;

Enjoy coding ...
have fun :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Using jQuery you can easily remove the checkbox. ASP.NET Gridview generating mark up as HTML table in the browser. By using that html table id you can loop through all rows and cols like below using jquery.

$('table#yourTable tr').each(function(){
  var isEmpty = true;
  // Process every column
    // If data is present inside of a given column let the row know
    if($.trim($(this).html()) == '') {
  // If the whole row is empty remove it from the dom
JemiM 29-Jan-13 8:07am
By using jQuery and Javascript you can easily manipulate the DOM(each element in your page) elements. If you are a webdeveloper you should study jQuery and Javascript. So you can avoid a lot of server side code that you have written inside the code behind.that increase your web application performance because the client script run the browser itself.
JemiM 29-Jan-13 8:11am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,180
Maciej Los 2,453
Jochen Arndt 1,910
ppolymorphe 1,785

Advertise | Privacy | Mobile
Web01 | 2.8.170518.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100