Click here to Skip to main content
15,890,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here i'm trying to display a gridview with header & footer row when there is no records in the gridview,but i'm taking checkboxes for deleting records so when there is no records that checkbox is shown.thanks in advances.
Posted
Comments
CRDave1988 2-May-12 2:40am    
Not very clear plese improve ur question and put ur .ascx or aspx code for display grid.
sadiq badami 2-May-12 5:45am    
this the code
String sqlSelectQuery = "SELECT PK_ID, EMP_NAME, EMP_AGE, EMP_SALARY FROM EMPLOYEE";
OleDbCommand oCommand = new OleDbCommand(oConnection, sqlSelectQuery);
OleDbDataAdapter oAdapter = new OleDbDataAdapter(oCommand);

//Create the DataSet object and fill it
DataSet oDataSet = new DataSet();
oAdapter.Fill(oDataSet);

//Check if the DataSet object is empty or not,
//if empty then add a blank row.
if(oDataSet.Tables[0].Rows.Count == 0)
{
oDataSet.Tables[0].Rows.Add(oDataSet.Tables[0].NewRow());
}

//Populate the GridView
gvMyGridView.DataSource = oDataSet;
gvMyGridView.DataBind();

1 solution

In RowDataBound event:
1. Look for row type as Header
2. Once found, use FindControl and get the checkbox.
3. Cast the found checkbox into local checkbox variable.
4. Do whatever you like with this checbox now. Disable it.

Done.

Sample:
C#
void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.Header)
    {
        // This is header row
        // You need to put null checks as per need
        CheckBox cb = (CheckBox)e.Row.FindControl("myCheckBox");
        cb.Enabled = false;
    }
}
 
Share this answer
 
Comments
VJ Reddy 2-May-12 10:20am    
5!
Sandeep Mewara 2-May-12 11:00am    
Thanks.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900