how to add one row in dropdown list [Resolved]

Posted by Sushant under C# on 6/25/2013 | Points: 10 | Views : 967 | Status : [Member] | Replies : 3
hi all
i have one dropdown list which is binded with one table
i want to add one row in that
i am using following code
ddlPropType.Items.Insert(0, new ListItem("Plot", String.Empty));
but its not working
plz responce

Sushat


Responses

Posted by: aswinialuri-19361 on: 6/25/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi Sushanth,

You mean you need to add an item
for that in aspx page you need to add <asp:listitem>myitem</asp:listitem>
in aspx.cs page ddlitem.item.add("myitem");

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Sushant, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 6/25/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Can you post your html code.

Sushant, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sushant on: 6/25/2013 [Member] Starter | Points: 25

Up
0
Down
.aspx file
<asp:DropDownList ID="ddlPropType" runat="server" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlPropType_SelectedIndexChanged" AutoPostBack="true">

</asp:DropDownList>

in .cs file code will be as follows
thanks

void BindPropertyType()
{
ddlPropType.Items.Clear();
//ddlPropType.Items.Insert(0, new ListItem("Plot", String.Empty));

cmd = new SqlCommand("Select NatureId,NatureType From ConstructionNatureMaster", cn);

SqlDataReader dr = cmd.ExecuteReader();
ddlPropType.DataSource = dr;

ddlPropType.DataTextField = "NatureType";
ddlPropType.DataValueField = "NatureId";
ddlPropType.DataBind();

dr.Close();
ddlPropType.Items.Add(new ListItem("Residential Plot", "1"));

}

Sushat

Sushant, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response