【发布时间】:2011-06-22 11:19:21
【问题描述】:
当我单击搜索按钮时,加载 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>");
}
}
【问题讨论】:
标签: c# asp.net gridview .net-2.0