2012-04-24 6 views
0

アップロードしたファイルの詳細をGridViewに表示するだけで、GridViewには1つの行しか表示されません。複数のファイルは許可されません。削除されたデータを表示するGridview

1行を削除して新しいファイルをアップロードしようとすると、2行(新しいファイルと削除されたファイル)が表示されています。

すでにGridView.DataSource = nullGridView.DataBind()を使用して試しました。

注:削除の後にGridViewを再バインドしましたが、削除されたファイルはまだ表示されます。私はこのような何かをしなければならなかったいくつかのケースでは

protected void DeleteLinkButton_Click(object sender, EventArgs e) 
{ 
    if (Session["name"] != null) 
    { 
     string strPath = Session["filepath"].ToString(); 
     System.IO.File.Delete(strPath); 

     GridView2.Rows[0].Visible = false; 
     Label8.Text = ""; 
     Session["filename"] = null; 
     Button3.Enabled = true; 
    } 

    GridView2.DataBind(); 
} 
+0

グリッドの 'DataSource'から削除する必要があります。 –

+0

私はgridview.datasource = nullとgridview.databind()を使ってみましたが、変更はありません – newuser1555

+0

ここで、データソースをgridviewに設定していますか?私は** DataBind()** –

答えて

0

Delete

//page level variable 
bool refreshRequired = false; 

protected void DeleteLinkButton_Click(object sender, EventArgs e) 
{ 
    if (Session["name"] != null) 
    { 
     string strPath = Session["filepath"].ToString(); 
     System.IO.File.Delete(strPath); 

     GridView2.Rows[0].Visible = false; 
     Label8.Text = ""; 
     Session["filename"] = null; 
     Button3.Enabled = true; 

     refreshRequired = true; 
    } 

} 

protected void Page_PreRender(object sender, EventArgs e) 
{ 
    if(refreshRequired) 
    { 
     //whatever you to to set your grids dataset, do it here 
     //but be sure to get the NEW data 
    } 
} 

は、あなたのグリッドが古いデータにバインドされています。データを変更するときは、データを新しいものに再バインドする必要があります。

関連する問題