Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > edit row from datagrid while hiding the record ID

Reply
Thread Tools

edit row from datagrid while hiding the record ID

 
 
Dica
Guest
Posts: n/a
 
      08-07-2007
i need to allow the user to select a row from my dataGrid for editing. as
such, i include the record ID in the first column and then extract like so
when retrieving the record details:

protected void gvLocations_edit(object sender, GridViewEditEventArgs e)
{
// load the record details into the edit fields //
GridView gvRecord = (GridView)sender;
string sThisRecord = gvRecord.Rows[e.NewEditIndex].Cells[0].Text;
...
}

i've been told i need to exclude the record ID from the datagrid, so i set
the column's visibility property to false. now my code fails as index[0] is
no longer the record id but a varChar column.

how to fix?

tks



 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      08-07-2007
"Dica" <(E-Mail Removed)> wrote in message
news:uE4ui.96672$xk5.46142@edtnps82...

>i need to allow the user to select a row from my dataGrid for editing. as
>such, i include the record ID in the first column and then extract like so
>when retrieving the record details:
>
> protected void gvLocations_edit(object sender, GridViewEditEventArgs e)
> {
> // load the record details into the edit fields //
> GridView gvRecord = (GridView)sender;
> string sThisRecord = gvRecord.Rows[e.NewEditIndex].Cells[0].Text;
> ...
> }
>
> i've been told i need to exclude the record ID from the datagrid, so i set
> the column's visibility property to false. now my code fails as index[0]
> is no longer the record id but a varChar column.
>
> how to fix?


You're using a GridView, not a DataGrid - it's really helpful to call things
by their correct names when posting in these newsgroups...

Hidden columns in GridViews are not rendered by default to the client as a
security measure - the DataKeyNames property should be used instead:
http://msdn2.microsoft.com/en-us/lib...es(vs.80).aspx

Alternatively, you can force the hidden column(s) to be databound and
rendered, but this is not recommended:

MyGridView.DataSource = <datasource>;
MyGridView.Columns[0].Visible = true;
MyGridView.DataBind();
MyGridView.Columns[0].Visible = false;


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie arrgh! - hiding cancel button on datagrid edit column CGW ASP .Net Web Controls 0 03-20-2006 04:00 PM
Snapshot restraint - edit, edit, edit Alan Browne Digital Photography 24 05-10-2005 10:15 PM
Snapshot restraint - edit, edit, edit Patrick Digital Photography 0 05-06-2005 10:53 PM
Edit All Function for DataGrid, and Moving the Edit Function in a DataGrid Schultz ASP .Net 3 02-14-2005 04:47 AM
Retrieving Record Key while creating the record. =?Utf-8?B?SnVzdGlu?= ASP .Net 4 10-05-2004 08:11 PM



Advertisments