Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6898933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:21:29+00:00 2026-05-27T07:21:29+00:00

I have Tab Container, and i have a GridView inside that. I need to

  • 0

I have Tab Container, and i have a GridView inside that. I need to upload image while i am clicking on the particular row. I am using update Panel too, outside of the grid view, i was able to upload image using PostBack Trigger to “preview Button”, but inside gridview i don know how to access it. I just created one button called btngrvPreview outside of the gridview and called its click event to the button btnPreview1 which is placed inside gridView. I think this approach is correct only.. But i don know why this Trigger to btnPreview1 is not working.

Its showing if(vFile.HasFile ) condition is always getting false..

Help me to solve this problem.

GridView

 <asp:GridView ID="grvItem" runat="server" AutoGenerateColumns="False" OnRowDataBound="grvItem_RowDataBound"                                                ShowFooter="True" SkinID="grid" Width="100%">  
    <Columns>                 
    <asp:BoundField HeaderText="Reference&nbsp;ID" />
    <asp:TemplateField HeaderText="Design">
<ItemTemplate>
<asp:Label ID="grvlbldesign" runat="server" CssClass="lbl">
    </asp:Label>
    </ItemTemplate>                 
    </asp:TemplateField>     
<asp:TemplateField HeaderText="Upload Image">
    <ItemTemplate>
<asp:HiddenField ID="hifgrvImage" runat="server" />
    <a ID="grvuploadimgPopup" runat="server">
    <asp:Image ID="grvUploadImage" runat="server" Width="90px" />
    </a>                                                                                 </ItemTemplate>             
    <EditItemTemplate>                                                                   
    <asp:FileUpload ID="fupImage1" runat="server" CssClass="fileuploadbtn" TabIndex="5" ToolTip="Browse For Image" Width="152px"/>         
    <asp:ImageButton ID="btnPreview1" runat="server" ImageUrl="~/images/view.gif" TabIndex="5" ToolTip="Preview" onclick="btngrvPreview_Click"/>
  </EditItemTemplate>                                                                        
</asp:TemplateField>     
    <Triggers>
    <asp:PostBackTrigger ControlID="btngrvPreview" />                   
    </Triggers>

Button Click EVent

protected void btnPreview1_Click(object sender, ImageClickEventArgs e)
 {
  try
     {
            int rowIndex = Convert.ToInt32(hifRecordID.Value);
            Image vimgView = (Image)grvItem.Rows[rowIndex].FindControl("grvUploadImage");
            System.Web.UI.WebControls.FileUpload vFile = (System.Web.UI.WebControls.FileUpload)grvItem.Rows[rowIndex].FindControl("fupImage1");

            string strimage;
            string strfilename, strextn;
            if (vFile.HasFile)
            {
                System.IO.Path.GetExtension(vFile.FileName);
                string strfileExtension = System.IO.Path.GetExtension(vFile.FileName).ToLower();
                string[] strAllowedFileExtensions = { ".gif", ".jpeg" };
                if (strfileExtension == ".jpeg")
                    strfileExtension = ".gif";
                if (FileExtensionIsApproved(strfileExtension) == true)
                {
                    strfilename = System.IO.Path.GetFileName(vFile.PostedFile.FileName);
                    strextn = System.IO.Path.GetExtension(strfilename);
                    strimage = ObjDataAccess.LoginName + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfffffff") + strextn;
                    ViewState["Filename"] = strimage;
                    string strpath = ConfigurationManager.AppSettings["ITEMPHOTO"] + strimage;
                    //Server.MapPath("empphoto") + "\\" + strimage;

                    vFile.PostedFile.SaveAs(strpath);
                    if (hifimgbrowser.Value == "IE")
                    {
                        vimgView.ImageUrl = strpath;
                        // tstimg.HRef = vimgView.ImageUrl;
                    }
                    else
                    {
                        vimgView.ImageUrl = "~/Handler.ashx?id=" + strpath;
                        // tstimg.HRef = imgView.ImageUrl;
                    }
                    vimgView.Visible = true;
                    System.IO.Stream fs = vFile.PostedFile.InputStream;
                    byte[] bytMyData = new byte[fs.Length + 1];
                    fs.Read(bytMyData, 0, Convert.ToInt32(fs.Length));
                    fs.Close();
                }
                else
                {
                    // DeleteImageFile();
                    vimgView.ImageUrl = "";
                    //  tstimg.HRef = "";
                    vimgView.Visible = true;
                }
            }
        }
        catch (Exception ex)
        {
            strMsg = ex.Message;
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "alertScript", "showMsgbox('" + strMsg + "','','2','');", true);
        }
    }

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:21:30+00:00Added an answer on May 27, 2026 at 7:21 am

    can you debug, and make sure that findcontrol method is not returning null, and also you place fileupload control in EditTemplate, so you have to check in this way in GridView _PreRender events

    if (this.GridView1.EditIndex != -1)
       {
         FileUpload upload = GridView1.Rows[GridView1.EditIndex].FindControl("fupImage1") as Button;
         if (upload != null)
          {
          //do something
          }
       }
    

    may be this will help you…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tab container with 5 tabs, each tab contains an update panel.
I am using Ajax tab container control with 3 tabs. I have placed a
I'm using ExtJS 3.2 and have content inside of a tab panel, and the
I have a tab container using <li> as the tab definition (common practice). The
I have a tab container, where i can add many tabs with long captions.
In tab container let say I have two tabs [Tab1 & Tab2] Tab1 has
I have a tab page that should be hidden if a property (BlahType) is
I have a tab container in aspx page and i want to enable disable
Looking for some implementation advice: I have a page that has a 3-tab ajaxToolkit:TabContainer.
I have an aspx page with an ajax tab container. In a class I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.