i have a custom webpart with dropdownlist control. i want the items of the dropdown to come from a custom list..
also i need the url of the custom list to be available on the toolpane view, when we modify webpart. can you pls redirect me to correct URL or guide. thanks
here's my code
public class DropDownWP : WebPart
{
DropDownList ddlCountry;
private string strMessage = "";
[Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
WebDisplayName("Enter source URL List (http://servername/lists/Sample.aspx)"),
WebDescription("Enter source URL List (http://servername/lists/Sample.aspx)"),
Category("Custom Category")]
public string Message
{
get { return strMessage; }
set { strMessage = value; }
}
protected override void CreateChildControls()
{
SPSite mySite = new SPSite("http://servername/en-US");
SPList targetList = targetSite.OpenWeb().Lists["List of Country"];
ddlCountry = new DropDownList();
foreach (SPListItem myItem in myList.Items)
{
ddlCountry.Items.Add(myItem["Title"].ToString());
}
this.Controls.Add(ddlCountry);
}
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{
writer.Write("<b>");
ddlCountry.RenderControl(writer);
writer.Write("</b>");
writer.Write("<br />");
writer.Write("<br />");
}
}