how to populate dropdownlist values from list in sharepoint

Advertisement

I created a ListDefination through VS2010 Name PopulateDropDown, In this I written code in Elements.xml

<Field Type="Choice"
DisplayName="Ticket"
Required="TRUE"
Group="PopulateDropDown Group"
ID="{E48F775E-1263-44A0-8B1C-39C7A2A4EDCF}"
StaticName="Severity"
Name="Ticket">
<CHOICES>
<CHOICE>Select</CHOICE>
<CHOICE>High</CHOICE>
<CHOICE>Medium</CHOICE>
<CHOICE>Low</CHOICE>
</CHOICES>
</Field>

and Schema.xml.

These values will display in List in Sharepoint.
But I have to populate these values in UserControl ascx page .



<div>
Ticket
<asp:DropDownList ID="ddlticket" runat ="server" >
</asp:DropDownList>

</div>

Now I am writing code to populate values in this dropdown list in ascx.cs
 public void ddlLoadTicket()
        {
            SPSite ositecollection = SPContext.Current.Site;
            using (SPWeb owebsiteroot = ositecollection.OpenWeb())
            {
                SPList list = owebsiteroot.Lists["PopulateDropDown"];
                SPFieldChoice field = (SPFieldChoice)list.Fields["Ticket"];
                ddlseverity.DataSource = field.Choices;
                ddlseverity.DataBind();
                }

                 }




Don't forget to call this method in PageLoad.


Finally you get the Result......
Advertisements
SHARE

Lakshmi Tulasi Jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a comment