Binding Dropdownlist in Edit Template of datagrid

Discussion in 'ASP .Net' started by =?Utf-8?B?VmljdG9yaW91czE=?=, Mar 13, 2007.

  1. 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>
     
    =?Utf-8?B?VmljdG9yaW91czE=?=, Mar 13, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?VmljdG9yaW91czE=?=

    Roland Dick Guest

    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
     
    Roland Dick, Mar 13, 2007
    #2
    1. Advertising

  3. 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
    >
    >
     
    =?Utf-8?B?VmljdG9yaW91czE=?=, Mar 15, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. San Diego Guy
    Replies:
    0
    Views:
    563
    San Diego Guy
    Aug 7, 2003
  2. Schultz
    Replies:
    3
    Views:
    576
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Feb 14, 2005
  3. keithb
    Replies:
    2
    Views:
    28,935
    keithb
    Jun 2, 2006
  4. Sharon McCarty
    Replies:
    0
    Views:
    265
    Sharon McCarty
    Nov 24, 2004
  5. Frank Kurka
    Replies:
    8
    Views:
    322
Loading...

Share This Page