Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have populated a grid view with some columns from database with following procedure sending a parameter:
C#
SqlConnection sqlConn = new SqlConnection(StringKoneksioni.Stringu);

           using (sqlConn)
           {
               SqlCommand sqlCmd = new SqlCommand("procProcedureName", sqlConn);

               sqlCmd.CommandType = CommandType.StoredProcedure;

               sqlCmd.Parameters.Add(new SqlParameter("@Parameter", SqlDbType.VarChar));

               sqlCmd.Parameters["@Parameter"].Value = Session["Parameter"];

               sqlConn.Open();

               SqlDataReader reader = sqlCmd.ExecuteReader();

               gvName.DataSource = reader;

               gvName.DataBind();

             ///All I want is to hide the following column from grid view but use its value. How to solve this?
               gvName.Columns[10].Visible = false;
               sqlConn.Close();

           }

P.S. My question is set on the comment code above.
Thank you in advance for your reply.
Cheers.
Posted

Here is the basic example about how to use gridview using item template (instead of using auto generated columns).
http://www.dotnetlearners.com/blogs/view/20/aspnet-gridview-basic-example-for-insert-update-and-delete-the-records.aspx[^]

Once you created the columns using item template you can then after databind just make the column visible false.

C#
  gvName.DataBind();

///All I want is to hide the following column from grid view but use its value. How to solve this?
  gvName.Columns[10].Visible = false;
 
Share this answer
 
Comments
dr_iton 16-Nov-15 10:16am    
I've got your point but the problem is that I'm populating the gridview from three tables and there must be some inner joins, If I use a boundfield, those columns are shown twice in the gridview. I can make visible=false any of boundfields but can not dissapear the values selected with stored procedure. If I'm not selecting that column the bounfield thows erros.
mrk raju 16-Nov-15 10:23am    
Have you set the property AutoGenerateColumns=false ?
dr_iton 16-Nov-15 11:01am    
Problem solved, thank you all.
Use an Item template and insert a hidden value or keeping your way , set display:none in that particular Bound field.
 
Share this answer
 
Comments
dr_iton 16-Nov-15 9:20am    
I never used before an Item template and don't know the procedure how to do that.

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