1

I have GridView with Template Column.Inside the template column i have asp:hiddenfield. I am binding the value using Eval() method.When i am trying to access the value of hiddenfi not accesible while visibility false ASPX

   <asp:TemplateField HeaderText="Select" Visible="false">
       <ItemTemplate>
           <asp:HiddenField ID="hdnMasterId" runat="server" 
              Value='<%# DataBinder.Eval(Container.DataItem, "Master_Id") %>' />
           <asp:CheckBox ID="chkDelete" runat="server" />
       </ItemTemplate>
       <ItemStyle Width="4%" HorizontalAlign="Center"></ItemStyle>
            <HeaderStyle HorizontalAlign="Center" />
   </asp:TemplateField>

CODE BEHIND

protected void gdvList_RowCommand(object sender, GridViewCommandEventArgs e)
{
    int intIndex = Convert.ToInt32(e.CommandArgument);
    GridViewRow row = gdvList.Rows[intIndex];
    HiddenField hdn = (HiddenField)row.FindControl("hdnMasterId");
}
2
  • Could you add your code? Mar 14, 2012 at 6:10
  • @ Mansoor Gee:-When i am trying to access the hiddenfield value its always null. Mar 14, 2012 at 11:07

2 Answers 2

1

If you set visibility="false" on a column it won't generate any html, thus wont have the hidden control. You need to put the hiddenfield elsewhere or hide the column with css/style instead.

4
  • :-Thanks for the reply...Whether the Same can be obtain by using asp:Label control? Mar 14, 2012 at 7:12
  • How do you mean? A Label will convert into a div tag and won't post anything back. Mar 14, 2012 at 9:54
  • i have added a label inside the templete column,its visibility false,now binding the text with the Master_Id.Now in the row_command i am getting the text value. Mar 14, 2012 at 11:16
  • I guess that is because the labels text is stored in the ViewState. If your try to change it with javascript you won't get the changes back to the server though. Mar 14, 2012 at 14:41
0

You could try as:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

 string strValue = ((HiddenField)GridView1.SelectedRow.Cells[cellindex].FindControl("HiddenFieldID")).Value;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.