我有四个与DropDownList
绑定的GridView
每当我填写DropDownList
时,数据都会显示在GridView
中
在四个DropDownList
中,我已将两个TextBox
附加到两个DropDownList
,以便通过TextBox
向DropDownList
添加新数据。
该数据将存储在数据库中,但不会显示在GridView
。
protected void Button4_Click(object sender, EventArgs e)
{
int flag = 0;
if (CheckBox1.Checked)
{
if (TextBox1.Text == "" && TextBox2.Text == "")
{
Label2.Text = "Enter Value !!";
TextBox1.Focus();
TextBox2.Focus();
Label2.Visible = true;
flag = 1;
}
else
{
}
}
if (flag == 0 && CheckBox1.Checked == true)
{
String strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("insert into CallCenter..Loy_DispMstr (CallType, SUBFormat,Disposition, SubDisposition) values (@CallType, @Format,@Disposition, @SubDisposition)", con);
cmd.Parameters.Add("@CallType", ddlCalltype.Text);
cmd.Parameters.Add("@Format", ddlFormat.Text);
cmd.Parameters.Add("@Disposition", TextBox1.Text);
cmd.Parameters.Add("@SubDisposition", TextBox2.Text);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
Label2.Visible = CheckBox1.Checked;
Label2.Text = " Your data is been saved in the database";
Label2.ForeColor = System.Drawing.Color.ForestGreen;
}
else { }
}
protected void Button2_Click1(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDispositionDetails();
}
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
String strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;
using (var con = new SqlConnection(strConnString))
{
con.Open();
using (cmd = new SqlCommand("ROMA_UserManagement", con))
{
cmd.Parameters.Add("@flag", SqlDbType.VarChar).Value = "0";
cmd.Parameters.Add("@CallType", SqlDbType.VarChar).Value = ddlCalltype.SelectedValue.ToString();
cmd.Parameters.Add("@Format", SqlDbType.VarChar).Value = ddlFormat.SelectedValue.ToString();
cmd.Parameters.Add("@disposition", SqlDbType.VarChar).Value = ddlDisp.SelectedValue.ToString();
cmd.Parameters.Add("@SubDisposition", SqlDbType.VarChar).Value = ddlSubdisp.SelectedValue.ToString();
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
da.SelectCommand = cmd;
da.Fill(dt);
}
con.Close();
}
gvDetails.DataSource = dt;
gvDetails.DataBind();
gvDetails.Visible = true;
}
答案 0 :(得分:1)
更新数据库后,您需要将数据绑定到GridView
。
在插入语句Button2_Click1(object sender, EventArgs e)
protected void Button4_Click(object sender, EventArgs e)
{
.......
........
Label2.Visible = CheckBox1.Checked;
Label2.Text = " Your data is been saved in the database";
Label2.ForeColor = System.Drawing.Color.ForestGreen;
//add this line
Button2_Click1(sender, e);
}