Find data after uploading images and bind data one page to another page

......................................source code.................................

<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .style1
        {
            height: 67px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table style="width: 946px">
    <tr>
    <td class="style1"></td>
    <td class="style1">
    <table>
    <tr>
    <td>Product&nbsp; Id</td>
    <td></td>
    <td>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
    <td>Product Name</td>
    <td></td>
    <td>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td></td>
    <td>
        &nbsp;</td>
    </tr>
    <tr>
    <td>
    </td>
    <td>&nbsp;</td>
    <td>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
                                </td>
                               
    </tr>
    </table>
    </td>
    <td class="style1"><table>
    <tr>
    <td>Select&nbsp; Id</td>
    <td>
        <asp:DropDownList ID="DropDownList1" runat="server" DataTextField="p_id"
            DataValueField="p_id" Height="23px" Width="96px">
        </asp:DropDownList>
                                </td>
    <td></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>
        &nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>Upload Image</td>
    <td>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        </td>
    <td></td>
    </tr>
    <tr>
    <td></td>
    <td>
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Submit" />
        </td>
    <td></td>
    </tr>
    <tr>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td><asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="false"
            onrowcommand="Gridview1_RowCommand"
        onselectedindexchanged="Gridview1_SelectedIndexChanged"
            onrowediting="Gridview1_RowEditing">
    <Columns>
    <asp:TemplateField HeaderText="Product Id">
    <ItemTemplate>
    <asp:Label ID="pid" runat="server" Text='<%#Bind("p_id") %>'/>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Product Name">
    <ItemTemplate>
    <asp:Label ID="pname" runat="server" Text='<%#Bind("p_name") %>'/>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Product Id">
    <ItemTemplate>
    <asp:Button ID="btn1" runat="server" CommandName="show" Text="Show" ToolTip="Show"  />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView></td>
   
    <td><asp:GridView ID="Gridview2" runat="server" AutoGenerateColumns="false"
            Visible="true" CaptionAlign="Right" HorizontalAlign="Right" PageSize="5">
    <Columns>
    <asp:TemplateField HeaderText="Image">
    <ItemTemplate>
    <asp:Image ID="img1" runat="server" Width="70px" Height="70px" ImageUrl='<%#Eval("p_image") %>' />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView></td>
    </tr>
    </table>
    </div>
    </form>
</body>
</html>
...................................end source code.................................
..................................code behind................................
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
    SqlDataAdapter da;
    DataSet ds = new DataSet();
    SqlCommand cmd;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            show();
            show1();
        }
    }
    protected void Gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
    {


                 GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);

                 Label id = (Label)row.FindControl("pid");
                 string id1 = id.Text.ToString();
                 da = new SqlDataAdapter("select p_image from category2 where p_id='" + id1 + "' ", con);
                 DataSet ds1 = new DataSet();
                 da.Fill(ds1);
                 Gridview2.DataSource = ds1;
                 Gridview2.DataBind();
                 Response.Redirect("Default2.aspx?id=" + id1 + "");
                
             
        
    }
    public void show()
    {
        da = new SqlDataAdapter("select *from product2", con);
        da.Fill(ds);
        Gridview1.DataSource = ds;
        Gridview1.DataBind();
    }
    
    public void show1()
    {
        da = new SqlDataAdapter("select p_id from product2", con);
        DataTable dt=new DataTable();
        da.Fill(dt);
        DropDownList1.DataSource = dt;
        DropDownList1.DataTextField = dt.Columns[0].ToString();
        DropDownList1.DataBind();
    }

    protected void Gridview1_SelectedIndexChanged(object sender, EventArgs e)
    {
        
    }
    protected void Gridview1_RowEditing(object sender, GridViewEditEventArgs e)
    {
     
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        con.Open();
        string str = "insert into product2 values(" + TextBox1.Text + ",'" + TextBox2.Text + "')";
        cmd = new SqlCommand(str,con);
        cmd.ExecuteNonQuery();
        con.Close();
        Response.Write("<script>alert('record saved!')</script>");
        show();
        show1();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string id=DropDownList1.SelectedValue.ToString();
        
        string name = FileUpload1.FileName;
        string path = Server.MapPath("");
        string pa = path + "//" + "image" +"//"+ name;
        FileUpload1.PostedFile.SaveAs(pa);
        string img = "~" + "/" + "image"+"/"+name;
        con.Open();
        string str = "insert into category2 values('" + id + "','" + img + "')";
        cmd = new SqlCommand(str,con);
        cmd.ExecuteNonQuery();
        con.Close();
        Response.Write("<script>alert('record saved!')</script>");
    }
}
...........................end code behind .....................................
............................get image this page.(sorce code)..................
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            height: 333px;
        }
        .style2
        {
            width: 242px;
        }
        .style3
        {
            width: 242px;
            height: 144px;
        }
        .style4
        {
            height: 144px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <table class="style1">
        <tr>
            <td class="style2">
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style3">
            </td>
            <td class="style4">
                <asp:GridView ID="Gridview2" runat="server" AutoGenerateColumns="False" 
                    CaptionAlign="Right" DataKeyNames="p_image" HorizontalAlign="Right" 
                    onselectedindexchanged="Gridview2_SelectedIndexChanged" PageSize="5">
    <Columns>
    <asp:TemplateField HeaderText="Image">
    <ItemTemplate>
    <asp:Image ID="img1" runat="server" Width="70px" Height="70px" ImageUrl='<%#Eval("p_image") %>' />
        <br />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
            </td>
            <td class="style4">
            </td>
        </tr>
        <tr>
            <td class="style2">
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    <div>
    
    </div>
    </form>
</body>
</html>
..................................end source code...................................
....................code behind.............................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Configuration;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
    SqlDataAdapter da;
    DataSet ds = new DataSet();

    protected void Page_Load(object sender, EventArgs e)
    {
        getimage();
    }
    public void getimage()
    {
        string str = Request.QueryString["id"].ToString();
        da = new SqlDataAdapter("select p_image from category2  where p_id='" + str + "' ", con);
        DataSet ds1 = new DataSet();
        da.Fill(ds1);
        Gridview2.DataSource = ds1;
        Gridview2.DataBind();
    }
    
        
    

    protected void Gridview2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

....................end code behind.....................................
Share:

No comments:

Post a Comment

Sunday, 16 December 2012

Find data after uploading images and bind data one page to another page

......................................source code.................................

<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .style1
        {
            height: 67px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table style="width: 946px">
    <tr>
    <td class="style1"></td>
    <td class="style1">
    <table>
    <tr>
    <td>Product&nbsp; Id</td>
    <td></td>
    <td>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
    <td>Product Name</td>
    <td></td>
    <td>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td></td>
    <td>
        &nbsp;</td>
    </tr>
    <tr>
    <td>
    </td>
    <td>&nbsp;</td>
    <td>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
                                </td>
                               
    </tr>
    </table>
    </td>
    <td class="style1"><table>
    <tr>
    <td>Select&nbsp; Id</td>
    <td>
        <asp:DropDownList ID="DropDownList1" runat="server" DataTextField="p_id"
            DataValueField="p_id" Height="23px" Width="96px">
        </asp:DropDownList>
                                </td>
    <td></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>
        &nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>Upload Image</td>
    <td>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        </td>
    <td></td>
    </tr>
    <tr>
    <td></td>
    <td>
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Submit" />
        </td>
    <td></td>
    </tr>
    <tr>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td><asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="false"
            onrowcommand="Gridview1_RowCommand"
        onselectedindexchanged="Gridview1_SelectedIndexChanged"
            onrowediting="Gridview1_RowEditing">
    <Columns>
    <asp:TemplateField HeaderText="Product Id">
    <ItemTemplate>
    <asp:Label ID="pid" runat="server" Text='<%#Bind("p_id") %>'/>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Product Name">
    <ItemTemplate>
    <asp:Label ID="pname" runat="server" Text='<%#Bind("p_name") %>'/>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Product Id">
    <ItemTemplate>
    <asp:Button ID="btn1" runat="server" CommandName="show" Text="Show" ToolTip="Show"  />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView></td>
   
    <td><asp:GridView ID="Gridview2" runat="server" AutoGenerateColumns="false"
            Visible="true" CaptionAlign="Right" HorizontalAlign="Right" PageSize="5">
    <Columns>
    <asp:TemplateField HeaderText="Image">
    <ItemTemplate>
    <asp:Image ID="img1" runat="server" Width="70px" Height="70px" ImageUrl='<%#Eval("p_image") %>' />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView></td>
    </tr>
    </table>
    </div>
    </form>
</body>
</html>
...................................end source code.................................
..................................code behind................................
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
    SqlDataAdapter da;
    DataSet ds = new DataSet();
    SqlCommand cmd;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            show();
            show1();
        }
    }
    protected void Gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
    {


                 GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);

                 Label id = (Label)row.FindControl("pid");
                 string id1 = id.Text.ToString();
                 da = new SqlDataAdapter("select p_image from category2 where p_id='" + id1 + "' ", con);
                 DataSet ds1 = new DataSet();
                 da.Fill(ds1);
                 Gridview2.DataSource = ds1;
                 Gridview2.DataBind();
                 Response.Redirect("Default2.aspx?id=" + id1 + "");
                
             
        
    }
    public void show()
    {
        da = new SqlDataAdapter("select *from product2", con);
        da.Fill(ds);
        Gridview1.DataSource = ds;
        Gridview1.DataBind();
    }
    
    public void show1()
    {
        da = new SqlDataAdapter("select p_id from product2", con);
        DataTable dt=new DataTable();
        da.Fill(dt);
        DropDownList1.DataSource = dt;
        DropDownList1.DataTextField = dt.Columns[0].ToString();
        DropDownList1.DataBind();
    }

    protected void Gridview1_SelectedIndexChanged(object sender, EventArgs e)
    {
        
    }
    protected void Gridview1_RowEditing(object sender, GridViewEditEventArgs e)
    {
     
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        con.Open();
        string str = "insert into product2 values(" + TextBox1.Text + ",'" + TextBox2.Text + "')";
        cmd = new SqlCommand(str,con);
        cmd.ExecuteNonQuery();
        con.Close();
        Response.Write("<script>alert('record saved!')</script>");
        show();
        show1();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string id=DropDownList1.SelectedValue.ToString();
        
        string name = FileUpload1.FileName;
        string path = Server.MapPath("");
        string pa = path + "//" + "image" +"//"+ name;
        FileUpload1.PostedFile.SaveAs(pa);
        string img = "~" + "/" + "image"+"/"+name;
        con.Open();
        string str = "insert into category2 values('" + id + "','" + img + "')";
        cmd = new SqlCommand(str,con);
        cmd.ExecuteNonQuery();
        con.Close();
        Response.Write("<script>alert('record saved!')</script>");
    }
}
...........................end code behind .....................................
............................get image this page.(sorce code)..................
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            height: 333px;
        }
        .style2
        {
            width: 242px;
        }
        .style3
        {
            width: 242px;
            height: 144px;
        }
        .style4
        {
            height: 144px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <table class="style1">
        <tr>
            <td class="style2">
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style3">
            </td>
            <td class="style4">
                <asp:GridView ID="Gridview2" runat="server" AutoGenerateColumns="False" 
                    CaptionAlign="Right" DataKeyNames="p_image" HorizontalAlign="Right" 
                    onselectedindexchanged="Gridview2_SelectedIndexChanged" PageSize="5">
    <Columns>
    <asp:TemplateField HeaderText="Image">
    <ItemTemplate>
    <asp:Image ID="img1" runat="server" Width="70px" Height="70px" ImageUrl='<%#Eval("p_image") %>' />
        <br />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
            </td>
            <td class="style4">
            </td>
        </tr>
        <tr>
            <td class="style2">
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    <div>
    
    </div>
    </form>
</body>
</html>
..................................end source code...................................
....................code behind.............................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Configuration;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
    SqlDataAdapter da;
    DataSet ds = new DataSet();

    protected void Page_Load(object sender, EventArgs e)
    {
        getimage();
    }
    public void getimage()
    {
        string str = Request.QueryString["id"].ToString();
        da = new SqlDataAdapter("select p_image from category2  where p_id='" + str + "' ", con);
        DataSet ds1 = new DataSet();
        da.Fill(ds1);
        Gridview2.DataSource = ds1;
        Gridview2.DataBind();
    }
    
        
    

    protected void Gridview2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

....................end code behind.....................................

No comments:

Post a Comment

Popular

Blog Archive

Total Pageviews

Archive