Display selected DataList Item in another page on Botton Click using C# and VB.Net in ASP.Net

Last Reply 2 months ago By dharmendr

Posted 2 months ago

how can connect a page of viewdetail to datalist detail button

when i click on view detail button then show a detail of one product on next page view detail button place in datalist

<asp:DataList ID="dlemp" runat="server" Font-Names="Verdana" Font-Size="X-Small"
    RepeatDirection="Horizontal" RepeatColumns="6" Width="99%" class="dlTable" HorizontalAlign="Center"
    Height="100%" BorderColor="Black" ShowFooter="False" ShowHeader="False">
    <ItemTemplate>
        <div id="pricePlans">
            <ul id="plans" style="border-bottom: 0px">
                <li class="plan">
                    <ul class="planContainer" style="border-bottom: 0px">
                        <li class="title">
                            <h2>
                                <asp:Label ID="ProductName" runat="server" Font-Size="X-small" Text='<%# Eval("ProductName") %>'></asp:Label>
                                <br />
                        </li>
                        <li class="title">
                            <%--<asp:Image ID="imgPhoto" runat="server" Width="100px" Height="100px" ImageUrl='<%# Bind("PhotoPath","~/photo/{0}") %>' />--%>
                            <asp:Image ID="imgEmp" runat="server" Width="50%" Height="50%" ImageUrl='<%# "data:image/jpg;base64," + Convert.ToBase64String((byte[])Eval("Data")) %>' />
                        </li>
                        <li>
                            <ul class="options">
                                <%-- <asp:Label style="text-align:justify" ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label><br />--%>
                                <li class="title">
                                    <h2>
                                        <asp:Label ID="Price" runat="server" Font-Size="X-small" CssClass="center" Text='<%# Eval("Price") %>'></asp:Label>
                                        <br />
                                </li>
                                <div style="margin-left: 8%">
                                    <li><b>Code: </b>
                                        <asp:Label ID="CustomerID" runat="server" Text=' <%# Eval("Product_id") %>'></asp:Label>
                                        <li style="width: 100%; font-size: x-small;"><a href="ViewDetails.aspx">Details</a>
                                            <%--<asp:Button ID="btn" runat="server" href="ViewDetails.aspx" CommandName="ViewDetails" CommandArgument='<%#Eval("Product_id") %>' BackColor="#FF9933"></asp:Button>--%>
                                        </li>
                                        <%-- <asp:CheckBox ID="CheckBox1" Text="select" runat="server" />--%>
                                        <asp:RadioButton ID="RadioButton1" Text="Select" runat="server" />
                                    </li>
                                </div>
                            </ul>
                    </ul>
                </li>
            </ul>
        </div>
    </ItemTemplate>
    <FooterTemplate>
    </FooterTemplate>
</asp:DataList>

 

 

You are viewing reply posted by: dharmendr 2 months ago.
Posted 2 months ago

Hi Sadia.net,

Check this example. Now please take its reference and correct your code.

HTML

Default

<asp:DataList ID="dlemp" runat="server" Font-Names="Verdana" Font-Size="X-Small"
    RepeatDirection="Horizontal" RepeatColumns="6" Width="99%" class="dlTable" HorizontalAlign="Center"
    Height="100%" BorderColor="Black" ShowFooter="False" ShowHeader="False">
    <ItemTemplate>
        <div id="pricePlans">
            <ul id="plans" style="border-bottom: 0px">
                <li class="plan">
                    <ul class="planContainer" style="border-bottom: 0px">
                        <li class="title">
                            <h2>
                                <asp:Label ID="ProductName" runat="server" Font-Size="X-small" Text='<%# Eval("ProductName") %>'></asp:Label>
                                <br />
                        </li>
                        <li class="title">
                            <asp:Image ID="imgEmp" runat="server" Width="50%" Height="50%" ImageUrl="~/Chrysanthemum.jpg" />
                        </li>
                        <li>
                            <ul class="options">
                                <li class="title">
                                    <h2>
                                        <asp:Label ID="Price" runat="server" Font-Size="X-small" CssClass="center" Text='<%# Eval("Price") %>'></asp:Label>
                                        <br />
                                </li>
                                <div style="margin-left: 8%">
                                    <li><b>Code: </b>
                                        <asp:Label ID="CustomerID" runat="server" Text=' <%# Eval("Product_id") %>'></asp:Label>
                                        <li style="width: 100%; font-size: x-small;"><a href="ViewDetails.aspx?Id=<%#Eval("Product_id") %>">
                                            Details</a> </li>
                                        <asp:RadioButton ID="RadioButton1" Text="Select" runat="server" />
                                    </li>
                                </div>
                            </ul>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </ItemTemplate>
    <FooterTemplate>
    </FooterTemplate>
</asp:DataList>

ViewDetails

<div>
    Name: <asp:Label ID="lblName" runat="server" /><br />
    Price: <asp:Label ID="lblPrice" runat="server" />
</div>

Namespace

C#

using System.Data;

VB.Net

Imports System.Data

Code

C#

Default

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        // Populate DataTable from Database.
        System.Data.DataTable dt = new System.Data.DataTable();
        dt.Columns.AddRange(new System.Data.DataColumn[] { 
                        new System.Data.DataColumn("Product_id", typeof(int)),
                        new System.Data.DataColumn("ProductName", typeof(string)),
                        new System.Data.DataColumn("Price",typeof(decimal)) });
        dt.Rows.Add(1, "Product 1", 1000);
        dt.Rows.Add(2, "Product 2", 1100);
        dt.Rows.Add(3, "Product 3", 1580);
        dt.Rows.Add(4, "Product 4", 1256);
        dlemp.DataSource = dt;
        dlemp.DataBind();
    }
}

ViewDetails

protected void Page_Load(object sender, EventArgs e)
{
    // Get Product_id from Query String.
    if (!string.IsNullOrEmpty(Request.QueryString["Id"]))
    {
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[] { 
                        new DataColumn("Product_id", typeof(int)),
                        new DataColumn("ProductName", typeof(string)),
                        new DataColumn("Price",typeof(decimal)) });
        dt.Rows.Add(1, "Product 1", 1000);
        dt.Rows.Add(2, "Product 2", 1100);
        dt.Rows.Add(3, "Product 3", 1580);
        dt.Rows.Add(4, "Product 4", 1256);
        // Filter record based on Product_id.
        DataTable product = dt.Select("Product_id=" + Request.QueryString["Id"]).CopyToDataTable();
        lblName.Text = product.Rows[0]["ProductName"].ToString();
        lblPrice.Text = product.Rows[0]["Price"].ToString();
    }
}

VB.Net

Default

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        ' Populate DataTable from Database.
        Dim dt As System.Data.DataTable = New System.Data.DataTable()
        dt.Columns.AddRange(New System.Data.DataColumn() {
                            New System.Data.DataColumn("Product_id", GetType(Integer)),
                            New System.Data.DataColumn("ProductName", GetType(String)),
                            New System.Data.DataColumn("Price", GetType(Decimal))})
        dt.Rows.Add(1, "Product 1", 1000)
        dt.Rows.Add(2, "Product 2", 1100)
        dt.Rows.Add(3, "Product 3", 1580)
        dt.Rows.Add(4, "Product 4", 1256)
        dlemp.DataSource = dt
        dlemp.DataBind()
    End If
End Sub

ViewDetails

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    ' Get Product_id from Query String.
    If Not String.IsNullOrEmpty(Request.QueryString("Id")) Then
        Dim dt As DataTable = New DataTable()
        dt.Columns.AddRange(New DataColumn() {
                            New DataColumn("Product_id", GetType(Integer)),
                            New DataColumn("ProductName", GetType(String)),
                            New DataColumn("Price", GetType(Decimal))})
        dt.Rows.Add(1, "Product 1", 1000)
        dt.Rows.Add(2, "Product 2", 1100)
        dt.Rows.Add(3, "Product 3", 1580)
        dt.Rows.Add(4, "Product 4", 1256)
        ' Filter record based on Product_id.
        Dim product As DataTable = dt.Select("Product_id=" & Request.QueryString("Id")).CopyToDataTable()
        lblName.Text = product.Rows(0)("ProductName").ToString()
        lblPrice.Text = product.Rows(0)("Price").ToString()
    End If
End Sub

Screenshot