none
Displaying selected value in ddl to another aspx pages RRS feed

  • Question

  • Hi, i have 2 dropdownlist to retrieve my data into a gridview

    and the gridview display the data according to the 2 dropdownlist value.

    The problem is my gridview have a column which have hyperlink to other pages, how to display the title(label) --> which display the 2 ddl value?

    and in the new pages there is one gridview showing only the selected hyperlink information.?

    Thanks.

    • Moved by Bob Shen Wednesday, August 15, 2012 9:57 AM (From:Visual C# General)
    Thursday, August 2, 2012 3:15 AM

All replies

    you can do one of following:-

    1.  You can use query string to do this.
    2. make link in gridview as command button then you can handle in command event

    Thursday, August 2, 2012 5:26 AM
  • Hi,

    Mind showing example or reference site?

    Thanks.

    Thursday, August 2, 2012 5:52 AM
  • Webform.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication3.WebForm1" %>
    
    <!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:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem>Dept 1</asp:ListItem>
                <asp:ListItem>Dept 2</asp:ListItem>
            </asp:DropDownList>
            <asp:GridView ID="GridView1" runat="server" DataKeyNames="Id" 
                onrowcommand="GridView1_RowCommand">
                <Columns>
                    <asp:HyperLinkField DataNavigateUrlFields="Id,Name" 
                        DataNavigateUrlFormatString="test.aspx?id={0}&amp;name={1}" Text="link" />
                    <asp:ButtonField CommandName="Action" Text="Button" />
                </Columns>
            </asp:GridView>
        
        </div>
        </form>
    </body>
    </html>
    

    Webform.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    
    namespace WebApplication3
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                GridView1.DataSource = GetDataTable();
                GridView1.DataBind();
            }
    
    
            DataTable GetDataTable()
            {
                DataTable dt = new DataTable("Employee");
                dt.Columns.Add("Id");
                dt.Columns.Add("Name");
                dt.Columns.Add("Salary");
    
                dt.Rows.Add("1", "Nasir", "100");
                dt.Rows.Add("2", "asdf", "100");
                dt.Rows.Add("3", "cvbb", "100");
                dt.Rows.Add("4", "hjjjj r", "100");
                return dt;
            }
    
            protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                if (e.CommandName == "Action")
                {
                    Session["ddlValue"] = DropDownList1.Text;
    
                    Session["employee"] = GridView1.DataKeys[int.Parse(e.CommandArgument.ToString())].Value;
                    Response.Redirect("test.aspx");
    
                }
            }
        }
    }

    test.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="WebApplication3.test" %>
    
    <!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:Label ID="Label1" runat="server" Text="Label">
            
            </asp:Label><br />
            <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
        </div>
        </form>
    </body>
    </html>
    
    test.aspx.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebApplication3
    {
        public partial class test : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                Label1.Text = "ddl : " + Session["ddlValue"];
                Label2.Text = "emplo : " + Session["employee"];
            }
        }
    }


    Thursday, August 2, 2012 7:00 AM
  • Hi, i do not have a button same as yours

    <asp:ButtonField CommandName="Action" Text="Button" />

    How to modify the code so that ,

    Whenever user click on the hyperlink,it goes to the other page which display the dropdownlist value as label.

    Thursday, August 2, 2012 7:30 AM
  • how is your code?
    Thursday, August 2, 2012 10:34 AM
  • <asp:TemplateField HeaderText="Project Name"> <ItemTemplate> <asp:HyperLink ID="hyper_Project" runat="server" Text='<%# Bind("PJName") %>' NavigateUrl='<%# "LOAssign.aspx?PJName="+Eval("CompanyID") %>' Target="_blank" ></asp:HyperLink> </ItemTemplate> <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="150px" /> </asp:TemplateField> >>This is the hyperlink within the gridview <asp:Label ID="lb_AcadYear" runat="server" > </asp:Label> <asp:Label ID="lb_AcadPeriod" runat="server" Visible="False"></asp:Label> <br /> <asp:Label ID="lb_Project" runat="server" Text="Project"></asp:Label> >> Label another aspx page to display the 2 dropdownlist value(previous page)-- AcadYear and AcadPeriod >> For lb_Project is to display the name of the project which is the hyperlink of a specified project that i click.

    I need help in displaying both dropdownlist and the project name.

    Thanks.

    Friday, August 3, 2012 1:37 AM
  • Hi XxjMxX,

    You are more likely to get more efficient responses to ASP.NET issues at http://forums.asp.net where you can contact ASP.NET experts.
     


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

    Friday, August 10, 2012 7:19 AM