ASP中如何用Button传递两个值给后台?
展开全部
ASP中用Button传递两个值给后台的方法:
1、在CommandArgument中用逗号分隔要传到后台的两个参数:
<asp:GridView ID="GridViewUserScraps" ItemStyle-VerticalAlign="Top" AutoGenerateColumns="False" Width="100%" runat="server" OnRowCommand="GridViews_RowCommand" >
<Columns>
<asp:TemplateField SortExpression="SendDate">
<ItemTemplate>
<asp:Button ID="btnPost" CssClass="submitButton" Text="Comment" runat="server" CommandName="Comment" CommandArgument='<%#Eval("ScrapId")+","+ Eval("UserId")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
2、C#后台接收到button传递的参数后的处理方法:
protected void GridViews_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Comment")
{
string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ',' });
string scrapid = commandArgs[0]; //传递参数1
string uid = commandArgs[1];//传递参数2
}
}
1、在CommandArgument中用逗号分隔要传到后台的两个参数:
<asp:GridView ID="GridViewUserScraps" ItemStyle-VerticalAlign="Top" AutoGenerateColumns="False" Width="100%" runat="server" OnRowCommand="GridViews_RowCommand" >
<Columns>
<asp:TemplateField SortExpression="SendDate">
<ItemTemplate>
<asp:Button ID="btnPost" CssClass="submitButton" Text="Comment" runat="server" CommandName="Comment" CommandArgument='<%#Eval("ScrapId")+","+ Eval("UserId")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
2、C#后台接收到button传递的参数后的处理方法:
protected void GridViews_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Comment")
{
string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ',' });
string scrapid = commandArgs[0]; //传递参数1
string uid = commandArgs[1];//传递参数2
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询