通过GridView模板的LinkButton的CommandArgument传递参数,传递一个参数是常用的,但是也可以传递多个参数
.aspx中的代码为:
view plaincopy to clipboardprint?
01.<asp:TemplateField HeaderText="课程编号" SortExpression="课程编号">
02. <ItemTemplate>
03. <asp:LinkButton ID="LinkButtonCourseNO" runat="server"
04. Text='<%# Bind("课程编号") %>' CommandName="ButtonClick"
05. CommandArgument='<%# Eval("ID")+","+Eval("课程名称")+","+Eval("Approved")%>'></asp:LinkButton>
06. </ItemTemplate>
07. </asp:TemplateField>
<asp:TemplateField HeaderText="课程编号" SortExpression="课程编号">
<ItemTemplate>
<asp:LinkButton ID="LinkButtonCourseNO" runat="server"
Text='<%# Bind("课程编号") %>' CommandName="ButtonClick"
CommandArgument='<%# Eval("ID")+","+Eval("课程名称")+","+Eval("Approved")%>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
.cs代码为:
view plaincopy to clipboardprint?
01.protected void GViewOutlineList_RowCommand(object sender, GridViewCommandEventArgs e)
02.{
03. if(e.CommandName == "ButtonClick")
04. {
05. //Response.Write(e.CommandArgument.ToString());
06. object [] arguments = e.CommandArgument.ToString().Split(',');
07. //Response.Write(arguments.Length.ToString());
08. //int OutlineID = Convert.ToInt32(e.CommandArgument);
09. Response.Redirect("a.aspx?OutlineID="+Convert.ToInt32(arguments[0])+"&CourseName="+arguments[1].ToString()+"&StateApproved="+Convert.ToInt32(arguments[2]));
10. }
11.}
本文来自CSDN博客,出处:http://blog.csdn.net/kdmhh/archive/2009/08/26/4485762.aspx