DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Tue, 07 Aug 2007 20:31:22 GMT,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Dica
          2    Mark Rae [MVP]


edit row from datagrid while hiding the record ID   
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
Date:Tue, 07 Aug 2007 20:31:22 GMT   Author:  

Re: edit row from datagrid while hiding the record ID   
"Dica"  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/library/system.web.ui.webcontrols.gridview.datakeynames(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
Date:Tue, 7 Aug 2007 22:06:34 +0100   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us