Binding Dropdownlist in Edit Template of datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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>
 
Victorious1 said:
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
 
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
 
Back
Top