0
我有四個DropDownList
,它們綁定到GridView
。
每當我填寫DropDownList
數據顯示在GridView
。
在四個DropDownList
中,我已將兩個TextBox
附加到兩個DropDownList
以通過TextBox
添加新數據到DropDownList
。
該數據正在存儲在數據庫中,但未在GridView
中顯示。新添加的數據沒有在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;
}
@ user31121992後的功能添加的最後一行一看便知。 –
我沒有得到請詳細說明 – user31121992
您需要在代碼中添加最後一行'Button2_Click1(sender,e);'。 –