hi friends..............
when ever registration is made automatically id will be generated...the id which are generated automatically whose id's are display on dropdown list...... i want code for displaying id's on droupdown list......
Loading
Satyapriya NayakPosted Feb 28, 2013, 3:05 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Dynamic_increment_using_Dropdown
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
int count;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Add("Select");
SqlConnection con = new SqlConnection(strConnString);
str = "select count(*) from employee";
com = new SqlCommand(str, con);
con.Open();
count = Convert.ToInt16(com.ExecuteScalar()) + 1;
DropDownList1.Items.Add("E00" + count);
con.Close();
}
}
protected void btn_insert_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "insert into employee values('" + DropDownList1.SelectedItem.Text.Trim() + "','" + txt_empname.Text.Trim() + "'," + txt_sal.Text.Trim() + ")";
com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();
Label4.Text = "Records successfully Inserted";
}
}
}
Neha SharmaPosted Feb 28, 2013, 2:34 AM
it ll fetch the id if you have write the dropdownlist1.seelctedvalue="id"; while binding the dropdownlist.
hope it ll solve your problem.