Hello peter,
Based on my understanding, you bound the "SelectedValue" property of
DropDownList by the datasource, and you encountered this error when you
clicked the "update" button in edit mode of GridView. Because the updated
GridView field data is not one of the values in DropDownList control.
Please feel free to let me know if I've misunderstood anything.
Could you please let me know how did you build the DropDownList? By static
ListItem or by datasource bound? If you bound DropDownList by static
ListItem, I suggest you bind it by a datasource. In this way, the new item
needs to be added in the datasource of DropDownList after you update the
GridView field so that the new item will be as one of the values of
DropDownList.
For example, we can create a DataSource control for DownDropList to bind
the same data table as GridView. After GridView field data is updated, the
related data table will be updated, which will impact the DropDownList.
Assuming that the following is the datasource of GridView:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [tbl]"
DeleteCommand="DELETE FROM [tbl] WHERE [id] = @id"
InsertCommand="INSERT INTO [tbl] ([link], [txt]) VALUES (@link,
@ txt)"
UpdateCommand="UPDATE [tbl] SET [link] = @link WHERE [id] = @id
">
<DeleteParameters>
<asp
arameter Name="id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp
arameter Name="link" Type="String" />
<asp
arameter Name="txt" Type="String" />
<asp
arameter Name="id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp
arameter Name="link" Type="String" />
<asp
arameter Name="txt" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
Assuming that the field "link" is the value field of the DropDownList ,
we
can create the SqlDataSource as below:
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString
%>"
SelectCommand="SELECT DISTINCT [link] FROM [tbl]">
</asp:SqlDataSource>
Then, we can bind it on DropDownList:
<asp
ropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource2" DataTextField="link" DataValueField="link"
SelectedValue='<%# Bind("link") %>' >
</asp
ropDownList>
In this way, after you update the GridView field data which is associated
with "link" field, the table "tbt" will be updated. The items of
DropDownList will be updated.
If the above can't help you out. Please post some code snippet.
Sincerely,
Vince Xu
Microsoft Online Support
£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working
with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½