前台代码:
<asp:GridView ID="ClientGridview" runat="server" AutoGenerateColumns="false" DataKeyNames="ClientID"
Font-Size="Small" OnRowCommand="ClientGridview_RowCommand">
<Columns>
<asp:BoundField DataField="ClientID" HeaderText="客户ID" ReadOnly="true" />
<asp:BoundField DataField="ClientName" HeaderText="客户名" />
<asp:ButtonField CommandName="ShowTeam" HeaderText="团队信息" Text="团队信息" />
<asp:ButtonField CommandName="ClientInfo" HeaderText="详细信息" Text="详细信息" />
</Columns>
</asp:GridView>
后台代码:
有两种操作:1.查看DetailsView中的信息(CommandName=ClientInfo)
2.转向另一个页面(CommandName=ShowTeam)
protected void ClientGridview_RowCommand(object sender, GridViewCommandEventArgs e)
{
conn = ConfigurationManager.AppSettings["str"];
con = new SqlConnection(conn);
con.Open();
int index = Convert.ToInt32((string)e.CommandArgument);
int ClientID = Convert.ToInt32(ClientGridview.DataKeys[index].Value.ToString());
Session["ClientID"] = ClientID;
if ((string)e.CommandName == "ShowTeam")
Response.Redirect("SearchTeamInfo.aspx");
else
{
if ((string)e.CommandName == "ClientInfo")
{
da = new SqlDataAdapter("select * from client where ClientID='" + ClientID + "'", con);
ds = new DataSet();
da.Fill(ds, "Client");
ClientDetailsView.DataSource = ds;
ClientDetailsView.DataBind();
}
}
con.Close();
}
本文介绍了一个使用ASP.NET实现的GridView控件示例,该控件具备显示客户信息并提供两种操作的功能:一是展示详细信息(CommandName=ClientInfo),二是跳转到另一个页面查看团队信息(CommandName=ShowTeam)。通过ButtonField触发不同CommandName实现不同业务逻辑。
4524

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



