Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET 2.0 DataGrid issue 1

Status
Not open for further replies.

djfrear

Programmer
Jul 11, 2007
83
GB
Hey guys,

Im working with a DataGrid in ASP.NET 2.0. Nothing fancy.

All I want to do is get the data from a cell within the selected row, nice and easy to do if the cell is set to visible:

Code:
        String MsgID;

        MsgID = gvInbox.SelectedRow.Cells[0].Text;

If the cell is set to visible, as I don't really need my users to see a particular field, the same line comes back with nothing.

Is there any way to get the data?

Regards, Daniel.
 
That was meant to be "if the cell is NOT set to visible
 
// Code for Grid
<asp:GridView ID="oGrid" runat="server">
<Columns>
<asp:BoundField DataField="Test" />
</Columns>
</asp:GridView>


// Code to Retrieve value
private void GetData()
{
string gridValue;
gridValue = oGrid.SelectedRow.Cells[0].Text;
}

If column is set to visible = false, you cannot extract the data from that cell. You can however, leave visible = true, and use a CSS to hide the column.

// CSS
.hide
{
display:none;
}

// Grid now looks like this with CSS applied

<asp:GridView ID="oGrid" runat="server">
<Columns>
<asp:BoundField DataField="Test">
<HeaderStyle CssClass="hide" />
<ItemStyle CssClass="hide" />
<FooterStyle CssClass="hide" />
</asp:BoundField>
</Columns>
</asp:GridView>

Cheers! Happy Coding...

 
Ah nice, that will do nicely mystique. Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top