SqlCommand cmd = new SqlCommand("spu_RetriveUserValue", SqlConObject); cmd.CommandType = CommandType.StoredProcedure; DataTable dt = new DataTable(); cmd.Parameters.Add("@EmpID", SqlDbType.VarChar).Value = id; SqlConObject.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); if (dt.Rows.Count > 0) { txtEmployeeName.Text = dt.Rows[0]["Employee_Name"].ToString(); ddlGender.SelectedItem.Value = dt.Rows[0]["Gender"].ToString(); txtDateOfJoining.Text = dt.Rows[0]["JoinedDate"].ToString(); txtAddress.Text = dt.Rows[0]["Employee_Address"].ToString(); ddlCountry.SelectedItem.Text = dt.Rows[0]["Country"].ToString(); int CountryID =Convert.ToInt32(dt.Rows[0]["Country_ID"]); Bind_ddlCity(CountryID); ddlCity.SelectedItem.Text = dt.Rows[0]["City"].ToString(); txtEMail.Text = dt.Rows[0]["Employee_Email"].ToString(); ddlDeptName.Text = dt.Rows[0]["Employee_Department"].ToString(); } else { lblError.Text = "No matching record found"; }
<pre lang="HTML"> <asp:DropDownList ID="ddlGender" runat="server"> <asp:ListItem>Select</asp:ListItem> <asp:ListItem Value="M">Male</asp:ListItem> <asp:ListItem Value="F">Female</asp:ListItem> </asp:DropDownList>
private void Fill_Combo() { try { combobox1.Items.Clear(); combobox1.DataSource = //Your select query from database to retrieve data. } catch (Exception ex) { throw ex; } combobox1.DataBind(); combobox1.Items.Insert(0, "--Select--"); combobox1.Focus(); }
ddlGender.SelectedItem.Text = (dt.Rows[0]["Gender"].ToString().Trim()=="M")?"Male":"Female";
ddlGender.SelectedValue = dt.Rows[0]["Gender"].ToString().Trim();
ddlGender.SelectedValue = dt.Rows[0]["Gender"].ToString();
ddlGender.SelectedItem.Text = dt.Rows[0]["Gender"].ToString();
ddlGender.Selectedindex=0;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)