0

这是页面加载代码

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //DropDownList Binding through bussiness logic
            Bussiness_logic.DropDownList_Bind(DDL_U, "SHORT_DESC", "UNIT_CODE", "UNIT_SOURCE");
            Bussiness_logic.DropDownList_Bind(DDL_Branch, "TYPE_DESC", "TYPE_CODE", "BRANCH_SOURCE");
        }
        if (Request.QueryString["File"] != null)
            {
                string fileNo = Request.QueryString["File"].ToString();
                Bussiness_logic.OpenConnection();
                SqlCommand com = new SqlCommand("LINK_DATA", Bussiness_logic.con);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@FILE", fileNo);
                SqlDataReader dtr = com.ExecuteReader();
                if (dtr.HasRows)
                {
                    dtr.Read();
                    {
                        TxtFile.Text = dtr["FILE_NO"].ToString();
                        DDL_Branch.SelectedValue = dtr["TYPE_DESC"].ToString();
                        TxtSub.Text = dtr["SUBJECT"].ToString();
                        DDL_U.SelectedValue = dtr["SHORT_DESC"].ToString();
                    }
                }

                Bussiness_logic.CloseConnection();
                Label1.Text = "";
            }
    }


我已经从另一个页面获取 QueryString 的值,并根据文件变量从与文件数据相对应的数据库中获取数据来归档我的字段。字段(两个文本框和两个 DropDwnList)正在正确填充,但是当我修改文本框或 DDL 中的数据并单击更新时按钮然后它不更新数据。
更新按钮代码

 protected void BtnUpdate_Click(object sender, EventArgs e)
    {
        Bussiness_logic.OpenConnection();
        SqlCommand com = new SqlCommand("UPDATE_DATA",Bussiness_logic.con);
        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.AddWithValue("@FILE_NO", TxtFile.Text);
        com.Parameters.AddWithValue("@SUB",TxtSub.Text);
        com.Parameters.AddWithValue("@UNIT",DDL_U.SelectedValue);
        com.Parameters.AddWithValue("@BRANCH",DDL_Branch.SelectedValue);
        com.ExecuteNonQuery();
        Label1.Text = "Action perfomed successfully !!!";
        Bussiness_logic.CloseConnection();
        Bussiness_logic.Empty_Control(TxtFile, TxtSub, DDL_U, DDL_Branch);
        //GridView1.Visible = false;
    }
4

1 回答 1

0
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //DropDownList Binding through bussiness logic
            Bussiness_logic.DropDownList_Bind(DDL_U, "SHORT_DESC", "UNIT_CODE", "UNIT_SOURCE");
            Bussiness_logic.DropDownList_Bind(DDL_Branch, "TYPE_DESC", "TYPE_CODE", "BRANCH_SOURCE");

        if (Request.QueryString["File"] != null)
            {
                string fileNo = Request.QueryString["File"].ToString();
                Bussiness_logic.OpenConnection();
                SqlCommand com = new SqlCommand("LINK_DATA", Bussiness_logic.con);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@FILE", fileNo);
                SqlDataReader dtr = com.ExecuteReader();
                if (dtr.HasRows)
                {
                    dtr.Read();
                    {
                        TxtFile.Text = dtr["FILE_NO"].ToString();
                        DDL_Branch.SelectedValue = dtr["TYPE_DESC"].ToString();
                        TxtSub.Text = dtr["SUBJECT"].ToString();
                        DDL_U.SelectedValue = dtr["SHORT_DESC"].ToString();
                    }
                }

                Bussiness_logic.CloseConnection();
                Label1.Text = "";
            }
         }
    }

将您的第二个if也放在第一个if。因为当您单击更新按钮时,您的页面加载事件首先触发。意味着您的文本框值再次从文本框设置。因此,如果停止在 postbask 上从数据库中设置文本框值,则将您的第二个放入第一个,

于 2013-07-17T05:40:40.960 回答