ASP.NET - Dropdownlist Extra item

Asked By Rahul
04-Feb-12 12:38 AM
i have dropdownlist box coding like this:

public void dropbind()

{

adap = new SqlDataAdapter("select * from serve", con);

ds =

new DataSet();

adap.Fill(ds);

DropDownList1.DataSource = ds;

DropDownList1.DataTextField = "servicename";

DropDownList1.DataValueField =

"id";

DropDownList1.DataBind();

}



i want to add Select field in that addionally first. what to do ?
  D Company replied to Rahul
04-Feb-12 12:58 AM
hello,

if i could understand your problem. than you requirement is one default item you want to bind to your grid, before actual data binding.

do this, before your binding code

DropDowinList1.Items.Insert(0, new ListItem("Default value"));
//and if u want it to be always selecte by default , than do like below.
DropDowinList1.SelectedIndex = 0;


Regard
D
  dipa ahuja replied to Rahul
04-Feb-12 03:40 AM
void bindDropDonw()
{
  string ConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  SqlDataAdapter da = new SqlDataAdapter("select empid from emp", ConnString);
 
  DataTable dt = new DataTable();
  da.Fill(dt); // Fill the dataset
 
  DropDownList1.DataSource = dt;
  DropDownList1.DataValueField = "empid";
  DropDownList1.DataTextField = "empid";
  DropDownList1.DataBind();
  DropDownList1.Items.Insert(0, "-Select-");
    
}
 
 
Create New Account
help
Sort Example< / h3> <table> <tr> <td> Sort by : <asp:dropdownlist ID = "SortList1" runat = "server" > <asp:listitem Selected = "true" > CustomerID< / asp:listitem> <asp:listitem> CompanyName< / asp:listitem> <asp:listitem> Address< / asp:listitem> <asp:listitem> City< / asp:listitem> <asp:listitem> PostalCode< / asp:listitem> <asp:listitem> Country< / asp:listitem> < / asp:dropdownlist> < / td> <td colspan
protected void Button4_Click( object sender, EventArgs e) { string SelectedItems = string .Empty; int i = 0; foreach ( ListItem item in CheckBoxList1.Items) { if (item.Selected) { if (i = = 1) { SelectedItems + = item.Text; } else { SelectedItems Insert query code } Hi Srikar, Try this code <asp:CheckBoxList runat = "server" ID = "test" > <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:ListItem Text = "3" Value = "3" > < / asp:ListItem> < / asp:CheckBoxList> foreach ( Item in test.Items) { if (Item
for saving the data to the database. Take a look at the screen shot below: ASP.Net GridView HTML Mark Up Now let’s create the method for saving the data to object sender, EventArgs e) { int rowIndex = 0; StringCollection sc = new StringCollection (); if (ViewState[ "CurrentTable" ] ! = null ) { DataTable dtCurrentTable = ( DataTable )ViewState[ "CurrentTable" ]; if (dtCurrentTable.Rows.Count > 0) { for ( int i = 1; i < = dtCurrentTable.Rows.Count the code above will show something like below with the entered values in the TextBox: ASP.Net GridView with Dynamic TextBoxes Clicking on the Save Button will insert the data to the database. Table a look at the Table below: ASP.Net GridView Records stored in SQL Server Database That’s it! Hope you will find this
server" Text = ' <%#Eval("Maritalstatus") %> '> < / asp : Label > < / ItemTemplate > < EditItemTemplate > < asp : RadioButtonList ID = "RadioButtonList1" runat = "server" > < asp : ListItem > Single < / asp : ListItem > < asp : ListItem > Married < / asp : ListItem > < / asp : RadioButtonList > < / EditItemTemplate > < FooterTemplate > < asp : RadioButtonList ID = "RadioButtonList1" runat = "server" > < asp : ListItem > Single < / asp : ListItem > < asp : ListItem > Married < / asp : ListItem > < / asp : RadioButtonList > < / FooterTemplate > < / asp : TemplateField > < asp : TemplateField HeaderText = "SpouseName"> < ItemTemplate > < asp : Label ID = "lblSpouseName" runat
asp.net C# Gridview linkbutton click event Hi all, I am using linkbutton inside the gridview. and asp:GridView> <asp:DropDownList ID = "ddlRooms" runat = "server" CssClass = "inputty2" AutoPostBack = "True" OnSelectedIndexChanged = "ddlRooms_SelectedIndexChanged"> <asp:ListItem> 1< / asp:ListItem> <asp:ListItem> 2< / asp:ListItem> <asp:ListItem> 3< / asp:ListItem> <asp:ListItem> 4< / asp:ListItem> <asp:ListItem> 5< / asp:ListItem> <asp:ListItem> 6< / asp:ListItem