I have a gridvew on my form with some fields . I added two fields to my gridview cause i wanted to use the data in them in my behind code and i fetch them in behind code, but the thing is i don’t want those columns to be visible in gridview, so i tried to set their visible attribute ‘False’ but that didn’t work, i didnt have access to their data. how can it be achieved?
<asp:BoundField DataField="Service_Id" HeaderText="Service_Id" SortExpression="Service_Id" HeaderStyle-BackColor="Gray"
Visible="true">
<HeaderStyle BackColor="Gray"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="UserId" HeaderText="UserID" SortExpression="UserId" HeaderStyle-BackColor="Gray"
Visible="true">
<HeaderStyle BackColor="Gray"></HeaderStyle>
</asp:BoundField>
And this is my page’s behind code :
Button Button1 = (Button)sender;
GridViewRow grdRow = (GridViewRow)Button1.Parent.Parent;
HiddenFieldServiceID.Value = grdRow.Cells[0].Text;
HiddenFieldUserID.Value = grdRow.Cells[1].Text;
You should not use
BoundFieldfor this. Use the DataKeyNames property instead.The values can then be fetched using
DataKeys[rowIndex]ASPX:
Code: