Fork me on GitHub

GridView控件使用经验

   GridView控件是Asp.net 1.1版本流行控件DataGrid的继承者,功能比DataGrid增强不少,但是也有很大的不同啊。将最近使用这个控件的经验同各位同学分享如下:
   1\掩藏字段的处理:DataGrid可以将字段直接设置为Visible=false,可以通过Cell[x].Text取到值。 GridView这个功能失效了,可以使用运行时来设定该列为掩藏。处理RowDataBound事件。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   e.Row.Cells[5].Visible = false;
}
   2\ 获取所选列的数据:DataGrid可以直接通过所选行来获取,GridView同样的代码无法运行。GridView 可以通过GridViewRow来获取。BtnAudit是模版列中的按钮。
GridViewRow grdRow = (GridViewRow)btnAudit.Parent.Parent;

 string strId = grdRow.Cells[0].Text;
 string memberId = grdRow.Cells[5].Text;
  3\ 最终删除一条数据之前进行确认,这个可以使用摸版列,在摸版列中放置按钮控件,其中有一个客户端事件onclientclick,这里可以写确认处理javascript脚本.例如:
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID="btnRefuse" runat="server" OnClick="btnRefuse_Click" Text="拒绝"  OnClientClick="return confirm(' 你真的要拒绝这个用户加入俱乐部?')"/>
                </ItemTemplate>
            </asp:TemplateField>


ObjectDataSource In Depth

Combining a BuildProvider and IExtenderProvider to create a declarative framework for conditional formatting in ASP.NET GridViews.
http://www.codeproject.com/aspnet/GridThemes.asp
posted @ 2005-12-22 23:06  张善友  阅读(42714)  评论(43编辑  收藏  举报