How to pass multiple values with Link Button Inside repeater to another page?

邮差的信 提交于 2019-12-11 06:42:44

问题


I have a Link Button Inside Repeater Control and I want pass to another page

<ItemTemplate>
    <tr>
        <td bgcolor="#D8E1EA" style="display: none">
            <asp:Label ID="empId" runat="server" Text='<% # Eval("emp_id")%>' />
        </td>
        <td>
            <asp:LinkButton ID="lnkRowSelection" runat="server" Text='<% # Eval("FullEmpName")%>' CausesValidation="false"
                CssClass="navigationlink" CommandName='<% # Eval("FullEmpName")%>' CommandArgument='<%#Eval("emp_id") %>'
                OnClick="ButtonLink_Click" ForeColor="black" Font-Underline="false" />
        </td>
        <td>
            <asp:Label ID="Label1" runat="server" Text='<% # Eval("days_worked")%>' />
        </td>
        <td>
            <asp:Label ID="Label2" runat="server" Text='<% # Eval("total_absents")%>' />
        </td>
        <td>
            <asp:Label ID="Label5" runat="server" Text='<% # Eval("days_marked")%>' />
        </td>
    </tr>
</ItemTemplate>

now I want to pass multiple values to Other Page (ManualAttendance.aspx) with Link Button I have tried this but with this i can only pass one value lnkRowSelection.Text Please tell me how can i pass multiple column values?? this is what i have tried

protected void ButtonLink_Click(object sender, System.EventArgs e)
{
    //LinkButton _lnkBtn = rptTeamAverage.Items[i].FindControl("lnkRowSelection") as LinkButton;
    LinkButton lnkRowSelection = (LinkButton)sender;
    //Label empId = (Label)sender;

    lnkRowSelection.PostBackUrl = "ManualAttendance.aspx?id=" + lnkRowSelection.Text + "&M=" + Request.QueryString["M"] + "&S=" + int.Parse(Request.QueryString["S"].ToString()) + "&sys=" + ((System.Collections.Generic.Dictionary<string, string>)Session["User"])["Token"];
}

回答1:


You can use semicolon separated values in the CommandArgument property of lnkRowSelection. Let's say you want to pass values of emp_id, days_worked, total_absents, and days_marked, here's what you need to add in the aspx code:

<asp:LinkButton ID="LinkButton1" 
    runat="server" 
    Text='<% # Eval("FullEmpName") %>' 
    CausesValidation="false"
    CssClass="navigationlink" 
    CommandName='<% # Eval("FullEmpName") %>' 
    CommandArgument='<%#Eval("emp_id") + ";" + Eval("days_worked") + ";" + Eval("total_absents") + ";" + Eval("days_marked") %>'
    OnClick="ButtonLink_Click" 
    ForeColor="black" 
    Font-Underline="false" />

then in ButtonLink_Click:

protected void ButtonLink_Click(object sender, System.EventArgs e)
{
    LinkButton lnkRowSelection = (LinkButton)sender;
    string[] arguments = lnkRowSelection.CommandArgument.Split(';');
    string emp_id = arguments[0];
    string days_worked = arguments[1];
    string total_absents = arguments[2];
    string days_marked = arguments[3];

    // pass emp_id, days_worked, total_absents, and days_marked to another page via query string
    Response.Redirect(string.Format("ManualAttendance.aspx?id={0}&daysworked={1}&totalabsents={2}&daysmarked={3}", emp_id, days_worked, total_absents, days_marked), false);
}


来源:https://stackoverflow.com/questions/21199924/how-to-pass-multiple-values-with-link-button-inside-repeater-to-another-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!