G
Guest
Hello,
I have a GridView bound to a custom object. I set the DataKeyNames property
along with the column DataField properties at design time, and bind the
GridView to my object at run-time. In the RowDeleting event, I try to access
the DataKeys property, but it contains no elements.
This is the first time I'm trying to use DatKeyNames and DataKeys. What am
I missing here?
Here is my code for the GridView:
<asp:GridView ID="grdPrograms" runat="server" AutoGenerateColumns="False"
DataKeyNames="ProgramID">
<Columns>
<asp:CommandField DeleteText="Remove" ShowDeleteButton="True" />
<asp:BoundField HeaderText="Residency Program" DataField="ProgramName"
ReadOnly="True" />
<asp:BoundField HeaderText="Start Date" DataField="StartDate"
HtmlEncode="False" DataFormatString="{0:d}" />
<asp:BoundField HeaderText="End Date" DataField="EndDate" HtmlEncode="False"
DataFormatString="{0:d}" />
</Columns>
</asp:GridView>
And here is my code to bind it:
grdPrograms.DataSource = Me.EditUser.GetUserPrograms().Values
grdPrograms.DataBind()
GetUserPrograms() returns a SortedDictionary(Of Integer, UserProgram). The
UserProgram class has properties ProgramName, StartDate, EndDate, and
ProgramID.
Any help here would be greatly appreciated!
Thank you,
Greg
I have a GridView bound to a custom object. I set the DataKeyNames property
along with the column DataField properties at design time, and bind the
GridView to my object at run-time. In the RowDeleting event, I try to access
the DataKeys property, but it contains no elements.
This is the first time I'm trying to use DatKeyNames and DataKeys. What am
I missing here?
Here is my code for the GridView:
<asp:GridView ID="grdPrograms" runat="server" AutoGenerateColumns="False"
DataKeyNames="ProgramID">
<Columns>
<asp:CommandField DeleteText="Remove" ShowDeleteButton="True" />
<asp:BoundField HeaderText="Residency Program" DataField="ProgramName"
ReadOnly="True" />
<asp:BoundField HeaderText="Start Date" DataField="StartDate"
HtmlEncode="False" DataFormatString="{0:d}" />
<asp:BoundField HeaderText="End Date" DataField="EndDate" HtmlEncode="False"
DataFormatString="{0:d}" />
</Columns>
</asp:GridView>
And here is my code to bind it:
grdPrograms.DataSource = Me.EditUser.GetUserPrograms().Values
grdPrograms.DataBind()
GetUserPrograms() returns a SortedDictionary(Of Integer, UserProgram). The
UserProgram class has properties ProgramName, StartDate, EndDate, and
ProgramID.
Any help here would be greatly appreciated!
Thank you,
Greg