Hi, I'm Daniel and I'm new in this group,
Sorry, but my english isn't good.
I have a problem when I use DataKeyNames in C#, I use SQL
server 2000 whit UniqueIdentifier in an ID register.
This is the code of GridView
<asp:GridView DataKeyNames="IdSitio"
ID="grdListadoDeSitio" runat="server" Caption="Listado de todos los
sitios" AutoGenerateColumns="False" AutoGenerateDeleteButton="True"
BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
CellPadding="2" ForeColor="Black" GridLines="None"
Font-Size="X-Small">
<Columns>
<asp:BoundField DataField="IdSitio"
HeaderText="IdSitio" ReadOnly="True" Visible="False" />
<asp:BoundField DataField="Nombre"
HeaderText="Sitio" ReadOnly="True" />
<asp:BoundField DataField="URL" HeaderText="URL"
ReadOnly="True" />
<asp:BoundField DataField="Comentario"
HeaderText="Comentario" ReadOnly="True" />
</Columns>
<SelectedRowStyle BackColor="DarkSlateBlue"
ForeColor="GhostWhite" />
<PagerStyle BackColor="PaleGoldenrod"
ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>
And I use to read the IdSitio this code:
Guid id = new
Guid(grdListadoDeSitio.SelectedDataKey["IdSitio"].ToString());
oSitiosAmigos.LoadByPrimaryKey(id);
But, I have this error message:
Object reference not set to an instance of an
object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Source Error:
Line 52: {
Line 53: // Guid id= new
Guid(grdListadoDeSitio.Rows[e.RowIndex].Cells[1].Text);
Line 54: Guid id = new
Guid(grdListadoDeSitio.SelectedDataKey["IdSitio"].ToString());
Line 55: oSitiosAmigos.LoadByPrimaryKey(id);
Line 56: oSitiosAmigos.MarkAsDeleted();
Source File: c:\Documents and Settings\Daniel\Mis documentos\Visual
Studio
2005\Projects\elpeloenelhuevo\elpeloblog\Altas\SitiosAmigos.aspx.cs
Line: 54
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
Altas_SitiosAmigos.grdListadoDeSitio_RowDeleting(Object sender,
GridViewDeleteEventArgs e) in c:\Documents and Settings\Daniel\Mis
documentos\Visual Studio
2005\Projects\elpeloenelhuevo\elpeloblog\Altas\SitiosAmigos.aspx.cs:54
System.Web.UI.WebControls.GridView.OnRowDeleting(GridViewDeleteEventArgs
e) +131
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row,
Int32 rowIndex) +732
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +1067
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String
eventArgument) +214
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+244
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+3840
If I use Guid id= new
Guid(grdListadoDeSitio.Rows[e.RowIndex].Cells[1].Text); with columns
visible=true I can read the ID...
Can help my pleas.
Thankyou
|
- [DotNetDevelopment] Question about DataKeyNames Daniel G. Samborski
-