By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,263 Members | 1,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,263 IT Pros & Developers. It's quick & easy.

selected value databinding for DropDownBox in gridview is Disabled

P: n/a

I am trying to bind the selected value of a databound dropdown box in a
databound gridview control to the value being displayed in the template
column the dropdown box has been added to. Both the grid and the dropdown
box are retrieving and displaying data fine, I just cant bind the two

I followed the instructions in the help document called 'Walkthrough:
Displaying a Drop-Down List While Editing in the GridView Web Server Control'
and the behavior I am getting is not as described in the help document.

After setting the ODS for both the gridview and the dropdown list (which was
added in an editItemTemplate), I went in to the DropDownList Tasks menu,
chose Edit DataBindings, but when I expected to modify the 'Binding for
Selected Value' options, they were greyed out (disabled). The ONLY available
method was the custom binding expression.

How can I get the 'Binding for Selected Value' options enabled? What am I

OR, what would be the Custom binding expression I should use to make it work.

Below is the code I am using. The control is the ddCountryRegion.

<asp:GridView ID="gvData" runat="server" CssClass="main-result-grid"
AutoGenerateColumns="False" DataSourceID="odsData">
<asp:BoundField DataField="CountryCode"
HeaderText="CountryCode" />
<asp:BoundField DataField="CountryName"
HeaderText="CountryName" />
<asp:BoundField DataField="BaseCurrency"
HeaderText="BaseCurrency" />
<asp:TemplateField HeaderText="CountryRegion">
<asp:DropDownList ID="ddCountryRegion"
runat="server" DataSourceID="odsRegionCol" DataTextField="key"
<asp:Label ID="lblCountryRegion"
runat="server" Text='<%# Bind("CountryRegion") %>'></asp:Label>
<asp:BoundField DataField="WonCountry"
HeaderText="WonCountry" />
<asp:BoundField DataField="PrimaryIndex"
HeaderText="PrimaryIndex" />
<asp:CommandField ShowEditButton="True" />
No Country Information has been found.
Thanks in advance for your help,

May 30 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Hi Dean,

Thank you for posting.

From your description, I understand you're buiding an data display page
through ASP.NET 2.0. The page contains one Gridview control which has a
template column with a dropdownlist in the editTemplate. However, you're
encountering some problem on set the dropdownlist's databinding property ,

Based on the aspx control template you provided, I think it is a quite
typical case of inner control databinding and in the VS IDE's design-time
interface, you should be able to edit the databinding field(SelectedValue
property) of the dropdownlist interactively... Anyway, here is a simple
Gridview's template I used in my local test project(which uses the
NorthWind database's Products/Categories tables):

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
<asp:TemplateField HeaderText="CategoryID"
&nbsp;<asp:DropDownList ID="DropDownList1"
runat="server" DataSourceID="SqlDataSource2"
DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>'>
&nbsp;<asp:DropDownList ID="DropDownList2"
runat="server" DataSourceID="SqlDataSource2"
DataValueField="CategoryID" Enabled="False" SelectedValue='<%#
Bind("CategoryID") %>'>

As you can see, the generated databinding expression for the dropdownlist
in the edittemplate is simply a

SelectedValue='<%# Bind("CategoryID") %>'


In addition, for customization on databinding of the nested controls in
GridView, you can also consider using the GridView's "RowDataBound" event.
We can find the certain control(dropdownlist) in the EditTemplate and
adjust its properties.

Hope this helps.


Steven Cheng
Microsoft Online Community Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure!
(This posting is provided "AS IS", with no warranties, and confers no

May 31 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.