更新后,gridview图像列在asp.net中变为空c# [英] After updating gridview image column is going null in asp.net c#

查看:42
本文介绍了更新后,gridview图像列在asp.net中变为空c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有一个网格视图,单击更新按钮后,图像列变为空.

我在图像存储过程中的数据类型是图像.

谁能帮我这个忙.

我的CS文件代码

Hello

I have a grid view, after clicking an update button the image column is going null.

My data type in stored procedure for image is image.

Can any one help me with this.

My code for cs file

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            //june25
            GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
            Label lblID = (Label)row.FindControl("lblID");
            //Image Image = (Image)row.FindControl("Image1");
            TextBox textName = (TextBox)row.FindControl("txtName");
            TextBox textDesc = (TextBox)row.FindControl("txtDesc");
            TextBox textImage = (TextBox)row.FindControl("txtImage");
            TextBox textActive = (TextBox)row.FindControl("txtActive");
            TextBox textCreatedBy = (TextBox)row.FindControl("txtCreatedBy");
            TextBox textCreatedDate = (TextBox)row.FindControl("txtCreatedDate");

            FileUpload FileUpload2 = (FileUpload)row.FindControl("FileUpload2");
            //FileUpload FileUpload2 = (FileUpload)GridView1.Rows[e.RowIndex].FindControl("FileUpload2");

            GridView1.EditIndex = -1;

            conn.Open();



            //SqlCommand cmd = new SqlCommand("UPDATE tbl_SqlImage set Name='" + textName.Text + "' , Description='" + textDesc.Text + "' , Image='" + textImage.Text + "' , Active='" + textActive.Text + "' , CreatedBy='" + textCreatedBy.Text + "' , CreatedDate='" + textCreatedDate.Text + "' where ID='" + lblID.Text.Trim() + "' ", conn);
            SqlCommand cmd = new SqlCommand("UPDATE tbl_SqlImage set Name='" + textName.Text + "' , Description='" + textDesc.Text + "' , Image='" + textImage.Text + "' , Active='" + textActive.Text + "' , CreatedBy='" + textCreatedBy.Text + "' , CreatedDate='" + textCreatedDate.Text + "' where ID='" + lblID.Text.Trim() + "' ", conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            bind();

            GridView1.DataBind();
            //june25

推荐答案

您好,

请通过以下链接:
在GridView中显示数据库中的图像 [ ^ ]
显示/存储并从数据库到Gridview检索图像数据,以及在鼠标悬停上 [ ^ ]
Hello,

Please go through below links:
Displaying Images from a Database in a GridView[^]
Display/Store and Retrieve Image Data from Database to Gridview, and also on Mouse Over[^]


您可以粘贴代码,该代码显示如何定义参数,以及SQL存储过程,这对于识别问题非常重要.

您需要在发送之前转换为字节流,这也可能会出错
Can you paste the code, which shows how parameters deined, also SQL Stored procedure which is very important to identify problem.

You need to convert to byte stream before sending, this can also go wrong


我猜您必须编写代码来绑定网格-我猜是丢失了.还有一件事是图像控件是否启用了ViewState?如果没有,请启用它.
I guess you have to write the code to bind the grid - which I guess is missing. And one more thing is that does the image control have the ViewState enabled? If not, please enable it.


这篇关于更新后,gridview图像列在asp.net中变为空c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆