0

私のプロジェクトでは、4 つのテンプレート Image(profilepic)、Label(firstname)、および Button1(accept)、button2(deny) と、リクエスターのアドレスを含む非表示フィールドを含むデータリストを含むリクエスト ページがあり、コード protected void を記述しました。 DataList1_ItemCommand(オブジェクト ソース, DataListCommandEventArgs e) {

    if (e.CommandName == "Accept")
    {
        SqlConnection con = new System.Data.SqlClient.SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["Con"].ConnectionString;
        con.Open();
        if (con.State == ConnectionState.Open)
        {
            HiddenField hd = (HiddenField)e.Item.FindControl("HiddenField1");
            string str = hd.Value;
            SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            cmd.CommandText = "Update requests set frnshpstatus='Y' where Email='" + Session["UserName"] + "' And frnemail='" + str + "'";
            cmd.Connection = con;
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();

        }
    }
    else if (e.CommandName == "Deny")
    {
        SqlConnection con = new System.Data.SqlClient.SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["Con"].ConnectionString;
        con.Open();
        if (con.State == ConnectionState.Open)
        {
            HiddenField hd = (HiddenField)e.Item.FindControl("HiddenField1");
            string str = hd.Value;
            SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            cmd.CommandText = "Update requests set frnshpstatus='N' where Email='" + Session["UserName"] + "' And frnemail='" + str + "'";
            cmd.Connection = con;
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
    }

}

承認ボタンをクリックすると、要求テーブルの frnshpstatus が「Y」として更新されますが、データリストに承認または拒否された要求がまだ表示されています。データリストからのみ削除して、リクエストの記録をデータベースに保持したい。c# を使用して asp.net で回答します。

4

2 に答える 2

0

「DataList1_ItemCommand」でDataListを再度バインドし、「DataList1_ItemDataBound」イベントに次のコードを記述する必要があります。DataListにバインドしているDataSourceに「frnshpstatus」があると想定しています...

void  DataList1_ItemDataBound(Object sender, DataListItemEventArgs e)
  {

     if (e.Item.ItemType == ListItemType.Item || 
         e.Item.ItemType == ListItemType.AlternatingItem)
     {
           DataRowView drv = (DataRowView)(e.Item.DataItem);        
           string frnshpstatus= drv.Row["frnshpstatus"].ToString(); 
           if(frnshpstatus="Y")
           {
             // Retrieve the Button control in the current DataListItem.
             Button Button1  = (Label)e.Item.FindControl("Button1");
             Button Button2  = (Label)e.Item.FindControl("Button2");
             Button1.Visible=False;
             Button2.Visible=False;

             //You Can Also Hide Row but for that you need to set it an ID and set it attribute "runat=server" 

             HtmlTableRow row=(HtmlTableRow)e.Item.FindControl("trId");
             row.Visible=False;   
           }                        

     }

  }
于 2012-08-25T06:18:01.823 に答える
0

承認または拒否をクリックした後、データリストから行を完全に削除したいと考えているのは正しいですか? その場合は、データリストにデータを入力するクエリに where 句を追加するだけです

where frnshpstatus is null

null でない場合は、デフォルト値が何であれ。次に、ItemCommand イベント ハンドラーの最後で受け入れ/拒否プロセスを完了した後、データリストを手動で再度データバインドする必要があります。

DataList1.DataBind();
于 2012-08-25T06:51:44.977 に答える