2015-11-14 47 views
1

我剛接觸.net。如何在gridview中用c#中的其他字段編輯圖像?

後臺代碼:

protected void Page_Load(object sender, EventArgs e) 
     { 

     }   

     protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
     { 
      SqlConnection con = Connection.DBconnection(); 
      if (e.CommandName == "EditRow") 
      { 
       GridViewRow gr = (GridViewRow)((Button)e.CommandSource).NamingContainer; 
       int index = gr.RowIndex; 
       hiddenfield.Value = index.ToString(); 
       Textid.Text = gr.Cells[0].Text; 
       Textusername.Text = gr.Cells[1].Text; 
       Textclass.Text = gr.Cells[2].Text; 
       Textsection.Text = gr.Cells[3].Text; 
       Textaddress.Text = gr.Cells[4].Text; 


      } 
      else if (e.CommandName == "Deleterow") 
      { 
       SqlCommand com = new SqlCommand("StoredProcedure4", con); 
       com.CommandType = CommandType.StoredProcedure; 
       com.Parameters.AddWithValue("@ID", Convert.ToInt32(e.CommandArgument)); 
       var id = Int32.Parse(e.CommandArgument.ToString());     
       com.ExecuteNonQuery(); 
       Response.Redirect("studententry.aspx"); 
      } 
     } 
     protected void GridView1_SelectedIndexChanged(Object sender, EventArgs e) 
     { 
      int index = GridView1.SelectedIndex; 
      hiddenfield.Value = index.ToString(); 
     } 

當我編輯的行,所有領域都顯示在文本框中預期影像存檔。

因爲最近我添加了圖像字段,並且我不知道如何編輯和更新圖像。

這裏是我的輸出screenshot

可我知道,又怎麼知道這個問題?

任何幫助將不勝感激。

感謝,

+0

StoredProcedure1,StoredProcedure2,StoredProcedure3,StoredProcedure4?你只是寫了很好的代碼而讓我的班級流失了。 –

回答

0
在編輯模式模板

,添加文本框而不是圖像控制與URL作爲文本屬性或添加FileUpload控件

相關問題