Pass (Send) ASP.Net Repeater Item Values to other Page using QueryString in C# and VB.Net

Last Reply one month ago By dharmendr

Posted one month ago

I have a repeater control with information of an employee.

My goal is to click on the item in the first Cell (Code) and pass the value of the item and the value of the date in the 4th column to a new web form in the form of a query string.

Please assist me with this.

<asp:Repeater ID="rpEmployeeMedicalReport" Visible="true" OnItemCommand="rpEmployeeMedicalReport_ItemCommand"
    runat="server">
    <HeaderTemplate>
        <table class="table table-striped table-hover table-condensed">
            <thead>
                <tr>
                    <th>Employee Code</th>                       
                    <th>Name</th>
                    <th>Surname</th>                       
                    <th>Date Of Medical</th>
                </tr>
            </thead>
            <tbody>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>                                         
            <td>
                <asp:LinkButton ID="EmployeeCode" OnClick="EmployeeCode_Click" runat="server" Font-Underline="true" Text='<%# Eval("Code") %>' CommandArgument='<%# Eval("Code") %>'></asp:LinkButton>
            </td>                   
            <td><asp:Label Text='<%#Eval("FirstName") %>' runat="server" ID="lblFirstName" /></td>                   
            <td><asp:Label Text='<%#Eval("LastName") %>' runat="server" ID="lblLastName" /></td>        
            <td><%#FormatDate(DataBinder.Eval(Container.DataItem, "DateOfMedical"))%></td> 
        </tr>   
    </ItemTemplate>
    <FooterTemplate>
        </tbody> </table>
    </FooterTemplate>
</asp:Repeater>
You are viewing reply posted by: dharmendr one month ago.
Posted one month ago

Hi Tevin,

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

HTML

Source

<asp:Repeater ID="rpEmployeeMedicalReport" Visible="true" runat="server">
    <HeaderTemplate>
        <table class="table table-striped table-hover table-condensed">
            <thead>
                <tr>
                    <th>Employee Code</th>
                    <th>Name</th>
                    <th>Surname</th>
                    <th>Date Of Medical</th>
                </tr>
            </thead>
            <tbody>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td>
                <asp:LinkButton ID="EmployeeCode" runat="server" Font-Underline="true" Text='<%# Eval("Code") %>'
                    PostBackUrl='<%# string.Format("~/Default.aspx?Code={0}&Date={1}",
                        HttpUtility.UrlEncode(Eval("Code").ToString()), HttpUtility.UrlEncode(Eval("DateOfMedical").ToString())) %>'>
                </asp:LinkButton>
            </td>
            <td><asp:Label Text='<%#Eval("FirstName") %>' runat="server" ID="lblFirstName" /></td>
            <td><asp:Label Text='<%#Eval("LastName") %>' runat="server" ID="lblLastName" /></td>
            <td><%#DataBinder.Eval(Container.DataItem, "DateOfMedical")%></td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </tbody> </table>
    </FooterTemplate>
</asp:Repeater>

Destination

<table>
    <tr>
        <td><b>Code</b></td>
        <td><asp:Label ID="lblCode" runat="server"></asp:Label></td>
    </tr>
    <tr>
        <td><b>Date</b></td>
        <td><asp:Label ID="lblDate" runat="server"></asp:Label></td>
    </tr>
</table>

Code

Source

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        System.Data.DataTable dt = new System.Data.DataTable();
        dt.Columns.AddRange(new System.Data.DataColumn[] { 
                        new System.Data.DataColumn("Code", typeof(int)),
                        new System.Data.DataColumn("FirstName", typeof(string)),
                        new System.Data.DataColumn("LastName",typeof(string)),
                        new System.Data.DataColumn("DateOfMedical",typeof(DateTime))});
        dt.Rows.Add(1, "John", "Hammond", DateTime.Now);
        dt.Rows.Add(2, "Mudassar", "Khan", DateTime.Now.AddDays(5));
        dt.Rows.Add(3, "Suzanne", "Mathews", DateTime.Now.AddDays(-3));
        dt.Rows.Add(4, "Robert", "Schidner", DateTime.Now.AddMonths(2));
        rpEmployeeMedicalReport.DataSource = dt;
        rpEmployeeMedicalReport.DataBind();
    }
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Dim dt As System.Data.DataTable = New System.Data.DataTable()
        dt.Columns.AddRange(New System.Data.DataColumn() {
                            New System.Data.DataColumn("Code", GetType(Integer)),
                            New System.Data.DataColumn("FirstName", GetType(String)),
                            New System.Data.DataColumn("LastName", GetType(String)),
                            New System.Data.DataColumn("DateOfMedical", GetType(DateTime))})
        dt.Rows.Add(1, "John", "Hammond", DateTime.Now)
        dt.Rows.Add(2, "Mudassar", "Khan", DateTime.Now.AddDays(5))
        dt.Rows.Add(3, "Suzanne", "Mathews", DateTime.Now.AddDays(-3))
        dt.Rows.Add(4, "Robert", "Schidner", DateTime.Now.AddMonths(2))
        rpEmployeeMedicalReport.DataSource = dt
        rpEmployeeMedicalReport.DataBind()
    End If
End Sub

Destination

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        lblCode.Text = HttpUtility.UrlDecode(Request.QueryString["Code"]);
        lblDate.Text = HttpUtility.UrlDecode(Request.QueryString["Date"]);
    }
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        lblCode.Text = HttpUtility.UrlDecode(Request.QueryString("Code"))
        lblDate.Text = HttpUtility.UrlDecode(Request.QueryString("Date"))
    End If
End Sub

Screenshot