<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbJoin" CommandName="joinSchool" Text="加入" CommandArgument='<%#DataBinder.Eval(Container,"RowIndex") %>' OnCommand="lbJoin_Command" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
后台: protected void lbJoin_Command(object sender,CommandEventArgs e)
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
int sch_id = Convert.ToInt32(SchoolView.DataKeys[rowIndex].Value);
if (Users.SetSchoolId(Convert.ToInt32(Session["UserID"]), sch_id))
{
Session["S_ID"] = sch_id;
Response.Redirect("FindClass.aspx");
}
else
{
insertHint.InnerHtml="<font color='red'>加入学校失败.请重试..</font>";
}
}
本文介绍了一个 ASP.NET 应用中如何通过 GridView 控件实现“加入学校”功能的具体实现方式。该功能允许用户点击按钮加入所选学校,并在后台通过 CommandName 和 CommandArgument 处理用户操作。
126

被折叠的 条评论
为什么被折叠?



