Hello everyone,

i have a gridview on my form, and i have some data which gets calculated once the user select a row, however the user does not need to see a specific column. Is there anyway that i dont display that certain column however be able to use the information that would have been displayed when the user selects it ???

can anyone help with i have tried to edit column and make the column Visible = False. It doesnt display the column, but it causes a big problem it doesnt not have field to extract information from so it compicates my situation.

please help.

Thanks in advance

Kushal

Dani AI

Generated

A couple of practical options that avoid showing a column while keeping the value available:

  • Use GridView.DataKeyNames to store per-row values (IDs, tokens, small non-sensitive fields). Note: DataKeys are persisted in ViewState by default and therefore travel to the browser as part of the page; they are not rendered as a visible column, but they are not purely server-side. For truly confidential data, keep only the row key in DataKeys and re-query the database or fetch the secret from a server-side store on postback.
  • Put a HiddenField inside a TemplateField when the value can safely be round-tripped to the client; it will render as an <input type="hidden"> and post back the value. As suggested, client-side hiding with CSS (visibility:hidden or display:none) also keeps the data in the rendered HTML but simply hides it from view.

Example (store keys in the GridView and read them in the selected-row handler):

<asp:GridView ID="GridView1" runat="server" DataKeyNames="Id,SecretValue" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
  <Columns>
    <asp:BoundField DataField="Name" HeaderText="Name" />
    <asp:ButtonField ButtonType="Button" Text="Select" CommandName="Select" />
  </Columns>
</asp:GridView>
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    var keys = GridView1.DataKeys[GridView1.SelectedIndex];
    var id = keys.Values["Id"];
    var secret = keys.Values["SecretValue"]; // available even though not shown as a column
}

Notes and troubleshooting: set DataKeyNames before calling DataBind (or in markup), and DataKeys are only available after binding. If you need absolute secrecy, do not send the secret to the client — store only an Id in DataKeys and fetch the sensitive value server-side. See the GridView.DataKeys docs and the HiddenField control docs for details: GridView.DataKeys/DataKeyNames and HiddenField control.

Recommended Answers

All 2 Replies

Try setting a css class to that column and setting the css style "visibility:hidden;". This way asp can still access the data but the user won't see it.

If the data is confidential then your best bet is to pull the data from DB on post back and work with it there.

Thank you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.