M
Mike P
I am creating a gridview that can be edited by the user, and one of the
fields to be edited I want to give the user a drop down which is
populated by a db field. This works fine when the current record being
edited already has a value for the dropdown, but there are cases where
the record might not have a value for the dropdown field, which means
that the SelectedValue property causes the app to crash as there is
nothing in the DB table to populate this record.
Here is my code for the field :
<asp:TemplateField HeaderText="Sponsor" SortExpression="Sponsor">
<ItemTemplate>
<asp:Label ID="lblSponsor" Text='<%#
Eval("Sponsor") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList ID="ddlSponsors"
runat="server" DataSourceID="SqlDataSource2"
DataTextField="Sponsor"
DataValueField="Sponsor" SelectedValue="Sponsor" />
</EditItemTemplate>
</asp:TemplateField>
Can anybody help?
fields to be edited I want to give the user a drop down which is
populated by a db field. This works fine when the current record being
edited already has a value for the dropdown, but there are cases where
the record might not have a value for the dropdown field, which means
that the SelectedValue property causes the app to crash as there is
nothing in the DB table to populate this record.
Here is my code for the field :
<asp:TemplateField HeaderText="Sponsor" SortExpression="Sponsor">
<ItemTemplate>
<asp:Label ID="lblSponsor" Text='<%#
Eval("Sponsor") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList ID="ddlSponsors"
runat="server" DataSourceID="SqlDataSource2"
DataTextField="Sponsor"
DataValueField="Sponsor" SelectedValue="Sponsor" />
</EditItemTemplate>
</asp:TemplateField>
Can anybody help?