How to import the excel sheet with images and save the data in database using asp .net

Last Reply one day ago By dharmendr

Posted 9 days ago

Hello Sir,

How to import the excel sheet with images and save the data in database using asp .net?

Please help me


You are viewing reply posted by: pandeyism 8 days ago.
Posted 8 days ago

Hi democloud,

You cannot override the same ItemTemplate two times in TemplateField.

Refer below sample code.


<asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server" EnableModelValidation="True">
    <AlternatingRowStyle BackColor="White" />
        <asp:TemplateField HeaderText="Id">
                <asp:Label ID="lblId" runat="server" Text='<% #Eval("ID") %>'></asp:Label>
        <asp:TemplateField HeaderText="Customer">
                <asp:Label ID="lblName" runat="server" Text='<% #Eval("Customer") %>'></asp:Label>
        <asp:TemplateField HeaderText="Country">
                <asp:Label ID="lblPrice" runat="server" Text='<% #Eval("Country") %>'></asp:Label>
        <asp:TemplateField HeaderText="Product Description">
            <   >
                <asp:Label ID="lblDescription" runat="server" Text='<% #Eval("Product") %>'></asp:Label>
                <asp:Image ID="image1" runat="server" ImageUrl="~/ClickHere.png" />
<asp:Button Text="Submit" runat="server" OnClick="Button2_Click" />



using System.Data;



protected void Page_Load(object sender, EventArgs e)
    DataTable dt = new DataTable();
    dt.Columns.AddRange(new DataColumn[] { new DataColumn("ID", typeof(int)), new DataColumn("Customer", typeof(string)), new DataColumn("Country", typeof(string)), new DataColumn("Product", typeof(string)) });
    dt.Rows.Add(1, "Mudassar", "India", "Bike");
    GridView1.DataSource = dt;

protected void Button2_Click(object sender, EventArgs e)
    foreach (GridViewRow g1 in GridView1.Rows)
        string ID = (g1.FindControl("lblId") as Label).Text;
        string Customer = (g1.FindControl("lblName") as Label).Text;
        string Country = (g1.FindControl("lblPrice") as Label).Text;
        string Product = (g1.FindControl("lblDescription") as Label).Text;
        Image Logo = g1.FindControl("image1") as Image;
        string query = "insert into Table values(" + ID + ",'" + Customer + "'," + Country + ",'" + Product + "','" + Logo.ImageUrl + "')";