Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Binding Dropdownlist in Edit Template of datagrid

Reply
Thread Tools

Binding Dropdownlist in Edit Template of datagrid

 
 
=?Utf-8?B?VmljdG9yaW91czE=?=
Guest
Posts: n/a
 
      03-13-2007
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>
<aspropDownList 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>
</aspropDownList>
 
Reply With Quote
 
 
 
 
Roland Dick
Guest
Posts: n/a
 
      03-13-2007
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>
> <aspropDownList 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>
> </aspropDownList>



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:

<aspropDownList 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>
</aspropDownList>

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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmljdG9yaW91czE=?=
Guest
Posts: n/a
 
      03-15-2007
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: <aspropDownList 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>
> > <aspropDownList 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>
> > </aspropDownList>

>
>
> 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:
>
> <aspropDownList 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>
> </aspropDownList>
>
> 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
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to initialize dropdownlist value in a gridview column edit template keithb ASP .Net 2 06-02-2006 09:58 PM
Snapshot restraint - edit, edit, edit Alan Browne Digital Photography 24 05-10-2005 10:15 PM
Snapshot restraint - edit, edit, edit Patrick Digital Photography 0 05-06-2005 10:53 PM
Edit All Function for DataGrid, and Moving the Edit Function in a DataGrid Schultz ASP .Net 3 02-14-2005 04:47 AM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM



Advertisments