How to get data from one page to another page through QueryString in Asp.Net?

....................default.aspx......................start......................
<%@ 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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td>
     <asp:FileUpload ID="flup" runat="server" />
    </td>
    </tr>
    <tr>
    <td>
    <asp:Button ID="btn_upload" runat="server" Text="Uplaod"
            onclick="btn_upload_Click" />
    </td>
    </tr>
    <tr>
    <td>
       <asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="false" >
    <Columns>
    <asp:TemplateField HeaderText="Images">
    <ItemTemplate>
    <asp:ImageButton ID="img_btn" runat="server" ImageUrl='<%#Eval("img_path") %>' CommandName="show" Width="70px" Height="70px"/>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </td>
    </tr>
    </table>
 
    </div>
    </form>
</body>
</html>
....................................end........................................
.................................default.aspx.cs....................................................
using System;
using System.Collections.Generic;
using System.Linq;
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 Default2 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
    }
    protected void btn_upload_Click(object sender, EventArgs e)
    {
        if (flup.FileName=="")
        {

            Response.Write("Please select a image...");
        }
        else
        {
            con.Open();
            string name = flup.FileName;
            string path = Server.MapPath("");
            string saveproject = path + "/" + "images" + "/" + name;
            flup.PostedFile.SaveAs(saveproject);

            string savedatabase = "~" + "//" + "images" + "//" + name;
            string str = "insert into uplaod_images1(img_path) values('" + savedatabase + "')";
            cmd = new SqlCommand(str, con);
            cmd.ExecuteNonQuery();
            con.Close();
            Response.Write("Upload image sucessfully..");
            bind_gridimage();
              
        }
        

    }
    protected void bind_gridimage()
    {
        con.Open();
       
        da = new SqlDataAdapter("select * from uplaod_images1",con);
        da.Fill(ds);
        Gridview1.DataSource = ds;
        Gridview1.DataBind();
        con.Close();
      
    }

    protected void Gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);

        Label id = (Label)row.FindControl("img_btn");
        string id1 = id.Text.ToString();

        da = new SqlDataAdapter("select img_path from uplaod_images1 where img_path=" + id1 + "", con);
        DataSet ds1 = new DataSet();
        da.Fill(ds1);
        Gridview1.DataSource = ds1;
        Gridview1.DataBind();
        Response.Redirect("Default3.aspx?id=" + id1 + "");
    }
}
...........................................end.......................
....................................default3.aspx............................................
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="grd_bind_image" runat="server" AutoGenerateColumns="false" DataKeyNames="img_path">
    <Columns>
    <asp:TemplateField HeaderText="Images">
    <ItemTemplate>
    <asp:ImageButton ID="img_btn" runat="server" ImageUrl='<%#Eval("img_path") %>' Width="70px" Height="70px"/>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </div>
    </form>
</body>
</html>

..................................end............................
,.......................................default3.aspx.cs...........................................
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 Default3 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            con.Open();
            string str = Request.QueryString["id"].ToString();
            string str1 = "select img_path from uplaod_images1 where img_path='" + str + "'";
            da = new SqlDataAdapter(str1, con);
            da.Fill(ds);
            grd_bind_image.DataSource = ds;
            grd_bind_image.DataBind();
            con.Close();
        }
    }
}
..................................end.................

Share:

No comments:

Post a Comment

Wednesday, 14 May 2014

How to get data from one page to another page through QueryString in Asp.Net?

....................default.aspx......................start......................
<%@ 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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td>
     <asp:FileUpload ID="flup" runat="server" />
    </td>
    </tr>
    <tr>
    <td>
    <asp:Button ID="btn_upload" runat="server" Text="Uplaod"
            onclick="btn_upload_Click" />
    </td>
    </tr>
    <tr>
    <td>
       <asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="false" >
    <Columns>
    <asp:TemplateField HeaderText="Images">
    <ItemTemplate>
    <asp:ImageButton ID="img_btn" runat="server" ImageUrl='<%#Eval("img_path") %>' CommandName="show" Width="70px" Height="70px"/>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </td>
    </tr>
    </table>
 
    </div>
    </form>
</body>
</html>
....................................end........................................
.................................default.aspx.cs....................................................
using System;
using System.Collections.Generic;
using System.Linq;
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 Default2 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
    }
    protected void btn_upload_Click(object sender, EventArgs e)
    {
        if (flup.FileName=="")
        {

            Response.Write("Please select a image...");
        }
        else
        {
            con.Open();
            string name = flup.FileName;
            string path = Server.MapPath("");
            string saveproject = path + "/" + "images" + "/" + name;
            flup.PostedFile.SaveAs(saveproject);

            string savedatabase = "~" + "//" + "images" + "//" + name;
            string str = "insert into uplaod_images1(img_path) values('" + savedatabase + "')";
            cmd = new SqlCommand(str, con);
            cmd.ExecuteNonQuery();
            con.Close();
            Response.Write("Upload image sucessfully..");
            bind_gridimage();
              
        }
        

    }
    protected void bind_gridimage()
    {
        con.Open();
       
        da = new SqlDataAdapter("select * from uplaod_images1",con);
        da.Fill(ds);
        Gridview1.DataSource = ds;
        Gridview1.DataBind();
        con.Close();
      
    }

    protected void Gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);

        Label id = (Label)row.FindControl("img_btn");
        string id1 = id.Text.ToString();

        da = new SqlDataAdapter("select img_path from uplaod_images1 where img_path=" + id1 + "", con);
        DataSet ds1 = new DataSet();
        da.Fill(ds1);
        Gridview1.DataSource = ds1;
        Gridview1.DataBind();
        Response.Redirect("Default3.aspx?id=" + id1 + "");
    }
}
...........................................end.......................
....................................default3.aspx............................................
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="grd_bind_image" runat="server" AutoGenerateColumns="false" DataKeyNames="img_path">
    <Columns>
    <asp:TemplateField HeaderText="Images">
    <ItemTemplate>
    <asp:ImageButton ID="img_btn" runat="server" ImageUrl='<%#Eval("img_path") %>' Width="70px" Height="70px"/>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </div>
    </form>
</body>
</html>

..................................end............................
,.......................................default3.aspx.cs...........................................
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 Default3 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            con.Open();
            string str = Request.QueryString["id"].ToString();
            string str1 = "select img_path from uplaod_images1 where img_path='" + str + "'";
            da = new SqlDataAdapter(str1, con);
            da.Fill(ds);
            grd_bind_image.DataSource = ds;
            grd_bind_image.DataBind();
            con.Close();
        }
    }
}
..................................end.................

No comments:

Post a Comment

Popular

Total Pageviews

Archive