Upload Image In Gridview using File Upload Control

Hi,

I have question that i want to upload image in Gridview for differt users. And i also don't know how to fix size while upload the image.Can You please tell me how to upload images for the different users and how to fix size so i can save all users name with their own logo image.

I just have started work with asp.net so i will be very thankful to you if you can give answer with code.

 

 

 

1
Nisha
11/27/2008 7:38:24 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

2 Replies
5113 Views

Similar Articles

[PageSpeed] 54
Get it on Google Play
Get it on Apple App Store

Hi, Nisha Shah

Based on my experience, please refer to the following code:

//HTML

        <asp:GridView ID="GridView1" runat="server" onrowcommand="GridView1_RowCommand">
            <Columns>
                <asp:TemplateField HeaderText="Upload">
                    <ItemTemplate>
                        <asp:FileUpload ID="FileUpload1" runat="server" />
                        <asp:Button ID="bt_upload" runat="server" EnableViewState="False" 
                            Text="Upload" CommandName="Upload"/>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
//Code
 
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        Button bts = e.CommandSource as Button;
        //Response.Write(bts.Parent.Parent.GetType().ToString());
        if (e.CommandName.ToLower() == "upload")
        {
            FileUpload fu = bts.Parent.Parent.FindControl("FileUpload1") as FileUpload;
            if (fu.HasFile)
            {
                Response.Write(fu.FileName);
            }
        }
    }
 

Gary yang - MSFT
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
1
Gary
12/2/2008 3:36:04 AM

 

 Hi, Please find below the code which helps you to solve your issue  
 
//HTML
<asp:GridView ID="GridView1" runat="server" OnRowCreated="GridView1_RowCreated" OnRowCommand="GridView1_RowCommand" >
            <Columns>
                <asp:TemplateField HeaderText="Store Logo">
                    <ItemTemplate>
                        <asp:FileUpload ID="flUpload" runat="server" /><br />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:Button ID="btnSave" runat="server" CausesValidation="False" CommandName="Save" Text="Save" />
                    </ItemTemplate>
                </asp:TemplateField>
          </Columns>
        </asp:GridView>
 
.cs file code
 
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
       
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Button btnSave = (Button)e.Row.FindControl("btnSave");
            //To get RowIndex in gridview RowCommand event
            if (btnSave != null )
            {
                btnSave.CommandArgument = Convert.ToString(e.Row.RowIndex);
            }
        }

    }
 
 
 
 
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (Convert.ToString(e.CommandName) == "Save")
        {
            GridViewRow row = GridView1.Rows[Convert.ToInt16(e.CommandArgument)];
            FileUpload flUp = (FileUpload)row.Cells[0].FindControl("flUpload");
            if (flUp.HasFile)
            {
                string filename = flUp.FileName;
                string extension = Path.GetExtension(filename);
                string filePath = "C:\\MyFolder";
                int userId = 110;
                filePath += "\\" + userId.ToString() + extension;
                flUp.SaveAs(filePath);
            }
        }

    }
 
 
Regarding cropping Image...
 
The following article and ASP.NET forum will shed some light on this..
 
http://michael.sivers.co.uk/post/2007/08/Crop-and-resize-an-image-in-ASPNET.aspx
 
http://forums.asp.net/p/1058837/1953286.aspx#1953286
 
Hope this helps
 
 
 
 
 
    

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Don't forget to click "Mark as Answer" on the post that helped you.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Thanks & Regards
Faisal. N
0
faisalnk
12/2/2008 4:41:58 AM
Reply:

Web resources about - Upload Image In Gridview using File Upload Control - asp.net.web-forms

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 1/15/2016 4:30:58 PM