Sie sind auf Seite 1von 2

Q.

How to bind a DropDown List


Ans.-----------------start
private void bind_dropdown_for_employee()
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new
SqlCommand("cre_client_manager_dropdown_for_part_3_pro", con))
{
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
ddl_assignto.DataSource = dt;
ddl_assignto.DataValueField = "emp_id";
ddl_assignto.DataTextField = "name";
ddl_assignto.DataBind();
ddl_assignto.Items.Insert(0, new ListItem("--Select Employee --",
"0"));
}
con.Close();
}
}
-----------------end

Q2. How to Insert a Value into database?


Ans.
-----------------Start
protected void Assign_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("cre_assign_work_pro",
con))
{
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Client_Id",
ddlassign_client.SelectedValue);
cmd.Parameters.AddWithValue("@Assign_to",
ddl_assignto.SelectedValue);
cmd.Parameters.AddWithValue("@Assign_by",
ddl_Assignby.SelectedValue);
cmd.Parameters.AddWithValue("@Work_Deadline",
DropDownList4.SelectedValue);

cmd.Parameters.AddWithValue("@work_discription",
txt_work_discription.Text);
SqlParameter sp_obj = new SqlParameter("@msg",
SqlDbType.VarChar, 100);
sp_obj.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(sp_obj);
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
ScriptManager.RegisterStartupScript(Page, this.GetType(),
"AlertMessage", "javascript:alert('" + sp_obj.Value.ToString() + "')", true);
clearfield();
}
else
{
ScriptManager.RegisterStartupScript(Page, this.GetType(),
"AlertMessage", "javascript:alert('" + sp_obj.Value.ToString() + "')", true);
}
}
con.Close();
}
}
-----------------end

Das könnte Ihnen auch gefallen