public void fillDDL() { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); try { //string str = "select MeetingType as Id from tbl_EventMeeting"; string str = "select Name as Id from [Come2myCityDB].[dbo].[tbl_Main_ID] where Sub_ID='2' and UserId='" + Convert.ToString(Session["User"]) + "'"; DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(str, con); da.Fill(ds); DDLMeetingType.DataSource = ds.Tables[0]; if (ds.Tables[0].Rows.Count > 0) { DDLMeetingType.DataValueField = "Id"; } DDLMeetingType.DataBind(); DDLMeetingType.Items.Add("Add New"); DDLMeetingType.Items.Add("Select"); DDLMeetingType.Items.Insert(0, new ListItem("Select", "0")); DDLMeetingType.SelectedIndex = 0; } catch (Exception ex) { throw ex; } }
public void txtChange(DropDownList ddl, TextBox tb) { string str1 = "select ID,Name from[Come2myCityDB].[dbo].[tbl_Main_ID] where Sub_ID='2'"; DataSet ds = new DataSet(); ds = cc.ExecuteDataset(str1); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (Convert.ToString(txtMeetingType.Text) == Convert.ToString(ds.Tables[0].Rows[i]["Name"])) { ViewState["abc"] = txtMeetingType.Text; } } if (Convert.ToString(txtMeetingType.Text) == Convert.ToString(ViewState["abc"])) { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('this type of Status Already Present')", true); DDLMeetingType.Visible = true; txtMeetingType.Visible = false; ViewState["abc"] = null; } else { string st = txtMeetingType.Text.ToUpper(); string str = "insert into [Come2myCityDB].[dbo].[tbl_Main_ID](Sub_ID,Name,UserId)values('2','" + txtMeetingType.Text + "','" + Convert.ToString(Session["User"]) + "')"; int status = cc.ExecuteNonQuery(str); DDLMeetingType.DataSource = ds; DDLMeetingType.DataTextField = "Name"; DDLMeetingType.DataValueField = "ID"; DDLMeetingType.DataBind(); DDLMeetingType.Items.Insert(0, new ListItem("0", "Select")); DDLMeetingType.SelectedIndex = 0; ddl.Visible = true; tb.Visible = false; } }