Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Hidden Field in Gridview ,

When i bind my dataset with gridview i want to hide the column of Hidden Field.

Now when i bind my dataset with gridview my hidden field column is visible.

Can anybody help out?

XML
<asp:TemplateField  >
                                     <ItemTemplate>
                                         <asp:HiddenField ID="Internal_id"  runat="server" Value='<%# Eval("ID") %>' />
                                     </ItemTemplate>
                                 </asp:TemplateField>



when i write <asp:TemplateField Visible = "false" >

the value is "" in hidden field , but i want the value in my hidden field.
Posted
Comments
JoCodes 14-Nov-13 1:18am    
Any specific reason you are using a hiddenfield instead of boundfield with visible false?
Member 9410081 14-Nov-13 2:53am    
FOR ID i dont want to show it but for update qury i need the hidden field.
Er Daljeet Singh 14-Nov-13 1:28am    
Are you sure that hidden field in displaying in the gridview when you run your page.

You should hide the Column. Don't set Visibility to false, otherwise it won't render the control.

Write below code in GridView RowCreated Event.
Here Cell 0 means first Column is used. You have to replace 0 with your required Column index.
C#
protected void OnRowCreated(object sender, GridViewRowEventArgs e)
{
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         e.Row.Cells[0].CssClass = "hiddencol";
     }
     else if (e.Row.RowType == DataControlRowType.Header)
     {
         e.Row.Cells[0].CssClass = "hiddencol";
     }
}

Write the following CSS on the aspx page.
CSS
.hiddencol
 {
     display:none;
 }
 
Share this answer
 
Comments
Member 9410081 14-Nov-13 2:55am    
Thanks.
Most welcome. Please accept the answer. :)
you can set visibility false from client side
C#
//Condition when you want to hide
IdOfGrid.Columns[2].Visible = false; 
// i am supposing it is your second column if not you can change it from 2 to whatever column it is 
 
Share this answer
 
v2
Hello ,

You can use Label instead on Hidden Field . then set

<asp:TemplateField Visible = "false" >


to get the Label value use this

Label  ID = dgvrow.Cells[6].FindControl("lblid") as Label;
//if lblid is label name and it is in 6th position
 if (ID != null)
int id = Convert.ToInt32(ID.Text);


and use this
id
value for further progress.

thanks
 
Share this answer
 

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