C# 如何从GridView编辑图像
这是我的aspx:C# 如何从GridView编辑图像,c#,asp.net,gridview,C#,Asp.net,Gridview,这是我的aspx: <td> <asp:FileUpload ID="fileupload" runat="server" /> </td> 插入所有详细信息后,显示如下所示: 这是用于从gridview编辑的: protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { SqlConnection con = Connection.DB
<td>
<asp:FileUpload ID="fileupload" runat="server" />
</td>
插入所有详细信息后,显示如下所示:
这是用于从gridview编辑的:
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;
}
}
当我从GridView
编辑特定行时,它将编辑图像
因此,图像是不可编辑的。我可以知道如何编辑图像吗?像这样试试
首先在Gridview控件内的图像控件旁边添加2个隐藏(hd_gv,hd_update)字段,另一个在表单中,并使用image src设置隐藏字段值
现在,在Gridview_row命令中,获取src并设置hd_update隐藏字段值,因此代码如下所示
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
SqlConnection con = Connection.DBconnection();
if (e.CommandName == "EditRow")
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
HiddenField imgSRC = (HiddenField)row.FindControl("hd_gv");
hd_update.Value=imgSRC.Value;
}
现在,在更新函数中,首先检查Fileupload控件是否有任何文件(如果有),然后上载该文件并使用新上载的文件更新图像src,否则设置hd_update(隐藏字段)值
单击按钮时更新代码如下所示
string Filename = hd_update.Value; // "HIDDEN_FIELD_IMAGE_SRC";
if (fileupload.HasFile)
{
//code to upload and set Filename variable with new file
Filename="NEW FILE NAME";
}
string Filename = hd_update.Value; // "HIDDEN_FIELD_IMAGE_SRC";
if (fileupload.HasFile)
{
//code to upload and set Filename variable with new file
Filename="NEW FILE NAME";
}