• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • Last Modified:

Formview dropdown help


In the below code is not working.
   SelectedValue='<%#DataBinder.Eval(Container.DataItem,"IssuanceMonth")%>'>
intelissense does not show selectedvalue, how can i populate the selected value .please help.
formview>
<ItemTemplate>
                  <td>
                                        <asp:DropDownList ID="ddlIssuanceMonth" runat="server"  Enabled="false"
                                            SelectedValue='<%#DataBinder.Eval(Container.DataItem,"IssuanceMonth")%>'>
                                        </asp:DropDownList>
                                    </td>
             

--codebehind

    protected void FVInvestigations_PreRender(object sender, EventArgs e)
    {
 DateTime month = Convert.ToDateTime("1/1/2000");
 for (int i = 0; i < 12; i++)
 {
     DateTime NextMont = month.AddMonths(i);
     ListItem list = new ListItem();
     list.Text = NextMont.ToString("MMMM");
     list.Value = NextMont.Month.ToString();
     ((DropDownList)(FVInvestigations.FindControl("ddlIssuanceMonth"))).Items.Add(list);
 }

Open in new window

0
Angela4eva
Asked:
Angela4eva
1 Solution
 
ankitkumar29Commented:
Unless you add list items, makes no sense to set selectedvalue

<asp:DropDownList ID="ddlIssuanceMonth" runat="server"  Enabled="false"
                                            SelectedValue='<%#DataBinder.Eval(Container.DataItem,"IssuanceMonth")%>'>
      

 <asp:ListItem Text="1" Value="1"></asp:ListItem>
    <asp:ListItem Text="2" Value="2"></asp:ListItem>
    <asp:ListItem Text="3" Value="3"></asp:ListItem>
                                     </asp:DropDownList>

Open in new window

0
 
guru_samiCommented:
---->intelissense does not show selectedvalue
SelectedValue is a non-browsable property and so it won't showup in .aspx intellisense or in designer Properties windows but you can still use it. It will show up in code-behind intellisense though.

---->how can i populate the selected value.
Are you getting any errors?
One thing you need to make sure is...your are doing:
list.Value = NextMont.Month.ToString();
So make sure "IssuanceMonth" returned from DB is same string format as list.Value.
OR
2: I think since  you are adding items to DDL in FV PreRender ... you might want to set the selectedValue of ddl in there after adding items..

((DropDownList)(FVInvestigations.FindControl("ddlIssuanceMonth"))).SelectedValue= "Month"
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now