当我单击搜索按钮时,加载Gridview。对于GridView,我可以添加,删除和更新。当用户单击添加时,弹出消息框“客户已成功添加” 然后我必须再次点击“SearchButton”。如果不能再看到GridView。 因为我只是通过单击“搜索”按钮来加载Gridview的代码。我该如何解决? 对于第一次,我只有一些下拉列表和搜索按钮。请帮我。谢谢
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
//Check if Add button clicked
if (e.CommandName == "AddProject")
{
try
{
//Get the values stored in the text boxes
string strProjectName = ((TextBox)GridView1.FooterRow.FindControl("txtPJDESCLONG")).Text;
string strLastUpdate = ((TextBox)GridView1.FooterRow.FindControl("txtLASTUPDATE")).Text;
string strStatus = ((TextBox)GridView1.FooterRow.FindControl("txtSTATUS")).Text;
string strUsername = ((TextBox)GridView1.FooterRow.FindControl("txtUSERNAME")).Text;
string strProjCode = ((TextBox)GridView1.FooterRow.FindControl("txtPJCODE")).Text;
//Prepare the Insert Command of the DataSource control
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(strConn);
string strSQL = "";
if (conn.State == ConnectionState.Closed) { conn.Open(); }
strSQL = "INSERT INTO CTORGPROJ (CTPAPBRCH,CTPAPDIV,CTPAPDEPT,CTPAPSECT,CTPAPSSEC,CTPAPPDIV,CTPAPLOC,CTPAPPDEP,PJCODE,PJDESCLONG,LASTUPDATE,STATUS, " +
"USERNAME) VALUES ('" + cboBranch.SelectedValue + "','" + cboDivision.SelectedValue + "','" + cboDepartment.SelectedValue + "','" + cboSection.SelectedValue + "','" + cboSubSection.SelectedValue + "','" + cboLocation.SelectedValue + "','" + cboPayDivision.SelectedValue + "','" + cboPayDepartment.SelectedValue + "','" + strProjCode + "','" + strProjectName + "','" +
strLastUpdate + "','" + strStatus + "','" + strUsername + "')";
Session.Add("conn", CookieUtil.GetTripleDESEncryptedCookieValue("sConn").Replace("-", ";"));
Session.Add("PjNo", CookieUtil.GetTripleDESEncryptedCookieValue("sPjCode"));
Session.Add("sComCode", CookieUtil.GetTripleDESEncryptedCookieValue("sComCode"));
string _strConn = Session["conn"].ToString();
_strConn = _strConn.Replace("Provider=SQLOLEDB;", "");
SqlDataSource SqlDataSource1 = new SqlDataSource(_strConn, strSQL);
SqlDataSource1.InsertCommand = strSQL;
SqlDataSource1.Insert();
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Customer added successfully');</script>");
GridView1.DataBind();
conn.Close();
conn.Dispose();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + ex.Message.ToString().Replace("'", "") + "');</script>");
}
}
答案 0 :(得分:0)
ShowGrid
将添加(如果需要)您的网格,绑定数据并使其可见。ShowGrid
方法。Page_Load
事件中,检查视图状态标志是否为真(在后置条件下),如果为真,则调用ShowGrid
方法。