473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Binding Dropdownlist in Edit Template of datagrid

When the editcommand is execured for my datagrid the dropdown list appears
for the bound item status. However, the item selected by default does not
match the unedited data. How do I make the dropdownlist selected item match
the correspond to the original data. HTML for dropdownlist below

<EditItemTemplate>
<asp:DropDownList ID="DropDownListStatus" runat="server" DataValueField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
DataTextField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
Width="172px">
<asp:ListItem Value="FOLLOW-UP">FOLLOW-UP</asp:ListItem>
<asp:ListItem Value="PENDING">PENDING</asp:ListItem>
<asp:ListItem Value="DISCHARGE">DISCHARGE</asp:ListItem>
<asp:ListItem Value="IN PROGRESS">NOT APPROPRIATE</asp:ListItem>
<asp:ListItem Value="NOT APPROPRIATE">SCREENING</asp:ListItem>
<asp:ListItem Value="SCREENING">SCREENING</asp:ListItem>
<asp:ListItem Value="NOT INTERESTED">NOT INTERESTED</asp:ListItem>
<asp:ListItem Value="LOST-TO-FOLLOWUP">LOST-TO-FOLLOWUP</asp:ListItem>
</asp:DropDownList>
Mar 13 '07 #1
2 7432
Victorious1 schrieb:
When the editcommand is execured for my datagrid the dropdown list appears
for the bound item status. However, the item selected by default does not
match the unedited data. How do I make the dropdownlist selected item match
the correspond to the original data. HTML for dropdownlist below

<EditItemTemplate>
<asp:DropDownList ID="DropDownListStatus" runat="server" DataValueField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
DataTextField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
Width="172px">
<asp:ListItem Value="FOLLOW-UP">FOLLOW-UP</asp:ListItem>
<asp:ListItem Value="PENDING">PENDING</asp:ListItem>
<asp:ListItem Value="DISCHARGE">DISCHARGE</asp:ListItem>
<asp:ListItem Value="IN PROGRESS">NOT APPROPRIATE</asp:ListItem>
<asp:ListItem Value="NOT APPROPRIATE">SCREENING</asp:ListItem>
<asp:ListItem Value="SCREENING">SCREENING</asp:ListItem>
<asp:ListItem Value="NOT INTERESTED">NOT INTERESTED</asp:ListItem>
<asp:ListItem Value="LOST-TO-FOLLOWUP">LOST-TO-FOLLOWUP</asp:ListItem>
</asp:DropDownList>

Hi,

I think the properties DataValueField and DataTextField are used only
when the elements for the drop down list are retrieved dynamically (from
a lookup table or something like that). But it looks like you have
static values in your drop down list and only want to select the one
that is in the database. For this, you need to bind the property
SelectedValue, in your example:

<asp:DropDownList ID="DropDownListStatus" runat="server" SelectedValue
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
DataTextField
<asp:ListItem Value="FOLLOW-UP">FOLLOW-UP</asp:ListItem>
<asp:ListItem Value="PENDING">PENDING</asp:ListItem>
<asp:ListItem Value="DISCHARGE">DISCHARGE</asp:ListItem>
<asp:ListItem Value="IN PROGRESS">NOT APPROPRIATE</asp:ListItem>
<asp:ListItem Value="NOT APPROPRIATE">SCREENING</asp:ListItem>
<asp:ListItem Value="SCREENING">SCREENING</asp:ListItem>
<asp:ListItem Value="NOT INTERESTED">NOT INTERESTED</asp:ListItem>
<asp:ListItem Value="LOST-TO-FOLLOWUP">LOST-TO-FOLLOWUP</asp:ListItem>
</asp:DropDownList>

Also, please note that you have a discrepancy between your text and your
values (In progress - Not appropriate; Not appropriate - Screening)

Hope this helps,

Cheers,

Roland

Mar 13 '07 #2
Thanks for pointing out the discrepancies. However, when I try to set the
selected value from HTML I get the following error message.

Parser Error
Description: An error occurred during the parsing of a resource required to
service this request. Please review the following specific parse error
details and modify your source file appropriately.

Parser Error Message: The 'SelectedValue' property is set only by the
runtime. It cannot be declared.

Source Error:
Line 134: </ItemTemplate>
Line 135: <EditItemTemplate>
Line 136: <asp:DropDownList ID="DropDownListStatus" runat="server"
Line 137: SelectedValue = '<%# DataBinder.Eval(Container,
"DataItem.screen_status") %>;'
Line 138: DataValueField = '<%# DataBinder.Eval(Container,
"DataItem.screen_status") %>'
Source File: c:\inetpub\wwwroot\BIC_WEB_ACCESS\Screening.aspx Line: 136
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET
Version:1.1.4322.2032

"Roland Dick" wrote:
Victorious1 schrieb:
When the editcommand is execured for my datagrid the dropdown list appears
for the bound item status. However, the item selected by default does not
match the unedited data. How do I make the dropdownlist selected item match
the correspond to the original data. HTML for dropdownlist below

<EditItemTemplate>
<asp:DropDownList ID="DropDownListStatus" runat="server" DataValueField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
DataTextField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
Width="172px">
<asp:ListItem Value="FOLLOW-UP">FOLLOW-UP</asp:ListItem>
<asp:ListItem Value="PENDING">PENDING</asp:ListItem>
<asp:ListItem Value="DISCHARGE">DISCHARGE</asp:ListItem>
<asp:ListItem Value="IN PROGRESS">NOT APPROPRIATE</asp:ListItem>
<asp:ListItem Value="NOT APPROPRIATE">SCREENING</asp:ListItem>
<asp:ListItem Value="SCREENING">SCREENING</asp:ListItem>
<asp:ListItem Value="NOT INTERESTED">NOT INTERESTED</asp:ListItem>
<asp:ListItem Value="LOST-TO-FOLLOWUP">LOST-TO-FOLLOWUP</asp:ListItem>
</asp:DropDownList>


Hi,

I think the properties DataValueField and DataTextField are used only
when the elements for the drop down list are retrieved dynamically (from
a lookup table or something like that). But it looks like you have
static values in your drop down list and only want to select the one
that is in the database. For this, you need to bind the property
SelectedValue, in your example:

<asp:DropDownList ID="DropDownListStatus" runat="server" SelectedValue
= '<%# DataBinder.Eval(Container, "DataItem.screen_status") %>'
DataTextField
<asp:ListItem Value="FOLLOW-UP">FOLLOW-UP</asp:ListItem>
<asp:ListItem Value="PENDING">PENDING</asp:ListItem>
<asp:ListItem Value="DISCHARGE">DISCHARGE</asp:ListItem>
<asp:ListItem Value="IN PROGRESS">NOT APPROPRIATE</asp:ListItem>
<asp:ListItem Value="NOT APPROPRIATE">SCREENING</asp:ListItem>
<asp:ListItem Value="SCREENING">SCREENING</asp:ListItem>
<asp:ListItem Value="NOT INTERESTED">NOT INTERESTED</asp:ListItem>
<asp:ListItem Value="LOST-TO-FOLLOWUP">LOST-TO-FOLLOWUP</asp:ListItem>
</asp:DropDownList>

Also, please note that you have a discrepancy between your text and your
values (In progress - Not appropriate; Not appropriate - Screening)

Hope this helps,

Cheers,

Roland

Mar 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: ShadowsOfTheBeast | last post by:
hi all i am trying to bind data to my datagrid from a listbox which i think it should work but an error is coming up saying i have to bind to a datasource that implements the Inumerable or...
2
by: rmorvay | last post by:
I am trying to dynamically build a dropdownlist and bind it to a cell in a grid. I tried to utilize the following code but I am stuck at the point where I bind the dropdownlist to the grid cell. ...
0
by: Wayneb | last post by:
Hi I have a datagrid with autogenerates columns based upon a dataset I have constructed from the results of database query - pretty noddy stuff. When you click on Edit I remove the standard...
0
by: Shane O. Pinnell | last post by:
I am sure this has come up before, but I haven't been able to find an answer as of yet. That said, any help is definitely appreciated! I have a datagrid populated from a dataset. I have a...
2
by: NewToDotNet | last post by:
Hi, I am very new to ASP.NET and web programming in general. I have one issue. I have a Datagrid object with Edit template. In one Datagrid row, I have 1 DropdownList, 1 textbox and 1 readonly...
1
by: Harold | last post by:
Hi all, having a little difficulty binding up a dropdownlist control in a datagrid column. I know I must be missing something Here are 2 methods. One is the DataGrid's ItemDataBound event to catch...
9
by: Timm | last post by:
I have an ASP.NET 2.0 page with two DropDownLists. I am using declarative data binding wherever possible and trying to minimize the use of code. The list of values in DropDownList DDL2 should be...
6
by: p.mc | last post by:
Hi all, I'm having major problems with a userControl which contains a datagrid. My problem concerns data binding. The Page_Load() procedure calls the DataBind procedure to bind the datagrid...
2
by: bmayer | last post by:
I am using a detail view and binding it to a sql data source (at some point in the future it will be an object data source). I have seen the article "Working with Data is ASP.NET 2.0 ::...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.