hi all,
I am trying to access the value of a hidden column(gridview column) but it doesn't show. But when I unhide(Visible = True) the column it shows the value. My code:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "editstate")
{
int index = Convert.ToInt32(e.CommandArgument);
txt_state_cd.Text = GridView1.Rows[index].Cells[0].Text;
txt_state_nm.Text = GridView1.Rows[index].Cells[1].Text;
}
HTML Code:
<
asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" Width="175px" OnRowDeleting="GridView1_RowDeleting" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="citystate_cd" ReadOnly="True" Visible="False" />
<asp:BoundField DataField="citystate_nm" HeaderText="State Name" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:ButtonField ButtonType="Image" ImageUrl="~/images/icon-edit.gif" Text="Edit" CommandName="editstate" />
<asp:CommandField ButtonType="Image" DeleteImageUrl="~/images/icon-delete.gif" ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="LightYellow" ForeColor="Gray" />
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
</asp:GridView>
I have used a bound field for "citystate_cd" but I have set its Visible property to False(coz I don't want to show this column, but want to access its value). It does work. Whereas if I set the Visible property to True then it works. I want that it sahould be hidden as well as I should be able to access the value.
Regards,
Royal
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).