Hi dear. please help me if any one knows my doubts.
How to dynamic increment using Dropdown list control with character for example E001
Reply me soon as possible.
Thanks&Regs
Magesh.A
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Dec 19, 2011, 7:51 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Dynamic_increment_using_Dropdown._Default" %>
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";
}
}
}
Thanks
Datta KharadPosted Dec 19, 2011, 1:11 AM
You can refer these articles:-
http://www.c-sharpcorner.com/UploadFile/mahesh/RandomNumber11232005010428AM/RandomNumber.aspx
http://stackoverflow.com/questions/3640174/generating-every-character-combination-up-to-a-certain-word-length