473,320 Members | 2,041 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,320 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 7430
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.