Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
I had also tried the coding as
GridView1.Columns[0].Visible = false

But not working...
the first column is an "id" field i need to hide.. but should not remove it...
Posted
Updated 22-Oct-19 21:59pm
Comments
ZurdoDev 21-Mar-14 6:34am    
Where did you put that code? Which event?
SViki 21-Mar-14 6:36am    
public void BindData()
{
con.Open();
cmd = new SqlCommand("select language_id, language_name ,language_desc from tbl_language where isactive=1 and ref_country_id = " + Convert.ToInt32(ddlCountry.SelectedValue.ToString()), con);
da = new SqlDataAdapter(cmd);
da.Fill(ds);

GridView1.DataSource = ds;
GridView1.DataBind();
GridView1.Visible = true;
// GridView1.Columns[0].Visible = false;

con.Close();
}
ZurdoDev 21-Mar-14 6:39am    
Because they are automatically generated you'll need to do it in a later event because they don't actually exist at that point, I believe. Is this winforms or asp.net?

1 solution

For your purpose, you should be using DataKeyNames[^]
Briefly, set the DataKeyNames property of the gridview to the id field. During databinding, the GridView will look for a field named id and used it the primary key for each row in the GridView. This way, you do not have to display the id yet still being able to retrieve it.
 
Share this answer
 
v2

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