有哪些ASP.NET GridView使用小窍门值得分享?

2026-04-30 08:516阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计153个文字,预计阅读时间需要1分钟。

有哪些ASP.NET GridView使用小窍门值得分享?

在GridView中嵌套控件示例——添加了一个LinkButton控件:asp:GridView ID=gv2 runat=server AutoGenerateColumns=false OnRowCommand=gv2_RowCommand>

gridview中嵌套控件示例 —— 添加了一个linkbutton

有哪些ASP.NET GridView使用小窍门值得分享?

前台:

<asp:GridView ID="gv2" runat="server" AutoGenerateColumns="false" OnRowCommand="gv2_RowCommand"> <Columns> <asp:BoundField DataField="pref_name" HeaderText="地区" /> <asp:TemplateField> <ItemTemplate> <asp:LinkButton runat="server" ID="gv_lbtn" Text="测试1" CommandArgument="<%# Container.DataItemIndex %>" CommandName="test1" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>

后台:

protected void gv2_RowCommand(object sender, GridViewCommandEventArgs e) { switch (e.CommandName) { case "test1": int rowIndex = Convert.ToInt32(e.CommandArgument); GridViewRow gr = gv2.Rows[rowIndex]; string alter = string.Format("alert(‘{0}‘)", gr.Cells[0].Text.Trim()); ScriptManager.RegisterStartupScript(Page, GetType(), "", alter, true); break; default: break; } }

标签:些小

本文共计153个文字,预计阅读时间需要1分钟。

有哪些ASP.NET GridView使用小窍门值得分享?

在GridView中嵌套控件示例——添加了一个LinkButton控件:asp:GridView ID=gv2 runat=server AutoGenerateColumns=false OnRowCommand=gv2_RowCommand>

gridview中嵌套控件示例 —— 添加了一个linkbutton

有哪些ASP.NET GridView使用小窍门值得分享?

前台:

<asp:GridView ID="gv2" runat="server" AutoGenerateColumns="false" OnRowCommand="gv2_RowCommand"> <Columns> <asp:BoundField DataField="pref_name" HeaderText="地区" /> <asp:TemplateField> <ItemTemplate> <asp:LinkButton runat="server" ID="gv_lbtn" Text="测试1" CommandArgument="<%# Container.DataItemIndex %>" CommandName="test1" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>

后台:

protected void gv2_RowCommand(object sender, GridViewCommandEventArgs e) { switch (e.CommandName) { case "test1": int rowIndex = Convert.ToInt32(e.CommandArgument); GridViewRow gr = gv2.Rows[rowIndex]; string alter = string.Format("alert(‘{0}‘)", gr.Cells[0].Text.Trim()); ScriptManager.RegisterStartupScript(Page, GetType(), "", alter, true); break; default: break; } }

标签:些小