<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>";
}
}