Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
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

C#
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
Posted
Updated 24-Jun-12 21:30pm
v3
Comments
ozturkmuhammed 25-Jun-12 3:31am    
if (IsPostBack) Did you put

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
 
Share this answer
 
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.
 
Share this answer
 
Comments
Nikil0012 25-Jun-12 3:37am    
public void bind()
{

conn.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM tbl_SqlImage", conn);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count != 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
conn.Close();

}
This is the bind() code. And i already tried viewstate enable option, not working please help
Pankaj Nikam 25-Jun-12 3:49am    
Is the image visible for the first time?
Nikil0012 25-Jun-12 4:25am    
yes, after adding it is visible, but at the time of updating it is not, please help
Pankaj Nikam 25-Jun-12 5:54am    
So the gridview has a image control and you bind it to a path right? Does the file exist on that path? Or is tha path visible if you simply run a query?
Nikil0012 25-Jun-12 7:42am    
Yes it exists but in binary format. like 0x53797374656D2E427974655B5D
Please check this article, It will help you
Image Handling In ASP.NET[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900