Hide recordId in DataGrid

  • Thread starter Thread starter szabelin
  • Start date Start date
S

szabelin

Hi, I was wondering if there is a way to have a
BoundColumn in DataGrid, but not display it? Basically I
would like to have a primary key hidden (and I need this
for edits and deletes).

I know I could store DataSet in the viewstate or session,
but I was just curios if DataGrid offers something (kind
of like Stringray's grid allowing you to associate a row
with data in a void* )

Thanks
 
That was the first thing I tried. I didn't work, text
values are "", maybe this has to do with the fact that asp
does not generate code for invisible controls. Have you
tried it?
 
szabelin said:
That was the first thing I tried. I didn't work, text
values are "", maybe this has to do with the fact that asp
does not generate code for invisible controls. Have you
tried it?

Yes. Assuming the column in question is the first column in the grid,
the following text returns the primary key value for a given record:

string id = DataGrid1.Items[x].Cells[0].Text;
 
Hm.. you must be doing something else because both str1
and str2 are empty (see code below). I am wondering if
there is an object type per row property built-into the
DataGrid, so developers don't have to "cheat" creating a
hidden column...


private void OnGridUpdate(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string str1 = this.grid.Items
[e.Item.ItemIndex].Cells[0].Text;
string str2 = e.Item.Cells[0].Text;

.....

}







-----Original Message-----
szabelin said:
That was the first thing I tried. I didn't work, text
values are "", maybe this has to do with the fact that asp
does not generate code for invisible controls. Have you
tried it?

Yes. Assuming the column in question is the first column in the grid,
the following text returns the primary key value for a given record:

string id = DataGrid1.Items[x].Cells[0].Text;

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com


.
 
Invisible controls are not rendered, that's correct. Can't you use hidden
fields for the record ids?

Jerry
 
szabelin,

I'm using a hidden field for my item ids in a datagrid and it's working
fine.

Here's the column from the datagrid:

<asp:boundcolumn visible="False" datafield="pk_EntryId"></asp:boundcolumn>

and here's how I get the value:

Dim EntryId As Int32 = CType(DataGrid1.SelectedItem.Cells(0).Text, Int32)

So you can get it to work.



Sincerely,


--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche


szabelin said:
Hm.. you must be doing something else because both str1
and str2 are empty (see code below). I am wondering if
there is an object type per row property built-into the
DataGrid, so developers don't have to "cheat" creating a
hidden column...


private void OnGridUpdate(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string str1 = this.grid.Items
[e.Item.ItemIndex].Cells[0].Text;
string str2 = e.Item.Cells[0].Text;

....

}







-----Original Message-----
szabelin said:
That was the first thing I tried. I didn't work, text
values are "", maybe this has to do with the fact that asp
does not generate code for invisible controls. Have you
tried it?

Yes. Assuming the column in question is the first column in the grid,
the following text returns the primary key value for a given record:

string id = DataGrid1.Items[x].Cells[0].Text;

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com


.
 
Back
Top