Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i used gridview in one page and trying to access that details in another page..because i have order now button in some other page where user is requested for selecting dealer name so when user clicks on order now button that grid data along with dealer name should go to the database..
Posted

 
Share this answer
 
XML
Here is my code... i have taken a page called image.aspx in that the following is the source code (which consists of a griview with hyperlink)

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="image.aspx.cs" Inherits="image" %>
    <!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>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White"
    BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1"
    DataKeyNames="QuickLook ID" DataSourceID="SqlDataSource1" GridLines="None">
    <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
    <Columns>
    <asp:BoundField DataField="Full Name" HeaderText="Full Name" SortExpression="Full Name" />
    <asp:BoundField DataField="Name Displayed" HeaderText="Name Displayed" SortExpression="Name Displayed" />
    <asp:BoundField DataField="Birth Day" HeaderText="Birth Day" SortExpression="Birth Day" />
    <asp:BoundField DataField="Access Level" HeaderText="Access Level" SortExpression="Access Level" />
    <asp:BoundField DataField="Team Name" HeaderText="Team Name" SortExpression="Team Name" />
    <asp:BoundField DataField="Joining Date" HeaderText="Joining Date" SortExpression="Joining Date" />
    <asp:HyperLinkField DataNavigateUrlFields="Quicklook Id" DataNavigateUrlFormatString="nextpage.aspx?id={0}"
    DataTextField="QuickLook ID" />
    </Columns>
    <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
    <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CalendarUtilityConnectionString %>"
    SelectCommand="SELECT * FROM [Employee_Record]"></asp:SqlDataSource>
    </div>
    </form>
    </body>
    </html>


After that i have taken another page called newpage.aspx in which i have a another gridview.. which diplays the details from the query string... as follows..
the following is the code behind for newpage.aspx file:

    protected void Page_Load(object sender, EventArgs e)
    {
    SqlConnection con = new SqlConnection(@"Data Source=WINKC185045-MAB\SQLEXPRESS;Initial Catalog=CalendarUtility;Integrated Security=True");
    SqlDataAdapter da = new SqlDataAdapter("select * from Employee_Record where [quicklook id] like '" + Request.QueryString[0] + "'", con);
    DataSet ds = new DataSet();
    da.Fill(ds, "employee_record");
    GridView1.DataSource = ds.Tables[0];
    GridView1.DataBind();
    }

Hope u found the solution !!!!!!!!
 
Share this answer
 
 
Share this answer
 
v2
Comments
Member 12484939 29-Apr-16 3:22am    
how to redirecting to another page using only one particular value which is present in gridview
Here is an example to access GridView from previous page. In first page set DataSource of the GridView to a DataTable using ds.Tables[0]. Then in Button click event add this DataTable in Session. In second page, get this DataTable from the session and bind it to GridView in second page:

In first page add GridView data source in session:
C#
protected void Page_Load(object sender, EventArgs e)
{
    string ConString = ConfigurationManager.ConnectionStrings["ConString2"].ConnectionString;
    SqlConnection con = new SqlConnection(ConString);
    string CmdString = "SELECT * FROM Departments";
    SqlCommand cmd = new SqlCommand(CmdString, con);
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    sda.Fill(ds);
    GridView2.DataSource = ds.Tables[0];
    GridView2.DataBind();
}

protected void Button1_Click(object sender, EventArgs e)
{
    DataTable dt = new DataTable();
    dt = (DataTable)GridView2.DataSource;
    Session.Add("MyDataTable", dt);
    Response.Redirect("WebForm2.aspx");
}


In second page get Data Source from the session:
C#
protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        DataTable dt = new DataTable();
        dt = (DataTable)Session["MyDataTable"];
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
}


Another solution is here:
http://www.aspsnippets.com/Articles/Pass-ASP.Net-GridView-from-one-page-to-another-page.aspx[^]
 
Share this answer
 
v2
Comments
Member 12484939 29-Apr-16 3:23am    
how to redirecting to another page using only one particular value which is present in gridview
Yes dear
keep it datatable all gridveiw
and take it anoter page by function parameter

Globally you have to make a function in cs.
suppose

C#
public public test(gridview gv)
{
}

acess the function by object
C#
com.test(dt);

and use it

[EDIT] added pre tags
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900