<asp:gridview>使用小结

1.默认的<asp:CommandField ShowEditButton="true" />灵活性不足,对于需要点击进入详细修改页面时,可以自己改造HyperLinkField实现:

如下:DataTextFormatString="修改"

 <asp:HyperLinkField DataNavigateUrlFields="NewsID" DataNavigateUrlFormatString="NewsEdit.aspx?NewsID={0}"
                    DataTextField="NewsTitle" HeaderText="编辑" DataTextFormatString ="修改" />

效果如下:

 

编辑

修改
修改
修改

 

总而跳转至NewsEdit.aspx?NewsID={0}进行详细修改!

 

2.待续~~~

完成后代码:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ConnectionStrings:ConnectionString%>"
            SelectCommand=" select * from News order by NewsID desc" DeleteCommand="delete from News where NewsID=@NewsID">
        </asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" DataSourceID="SqlDataSource1" ForeColor="#333333"
            BorderWidth="1px" RowStyle-HorizontalAlign="Center" CellPadding="3" GridLines="Vertical"
            Width="600px" DataKeyNames="NewsID" PageSize="15">
            <Columns>
                <asp:HyperLinkField DataNavigateUrlFields="NewsID" DataNavigateUrlFormatString="News.aspx?NewsID={0}"
                    DataTextField="NewsTitle" HeaderText="新闻标题" />
                <asp:BoundField DataField="NewsDate" HeaderText="发布时间" SortExpression="NewsDate" />
                <asp:BoundField DataField="NewsCategory" HeaderText="新闻种类" SortExpression="NewsCategory" />
                <asp:HyperLinkField DataNavigateUrlFields="NewsID" DataNavigateUrlFormatString="NewsEdit.aspx?NewsID={0}"
                    DataTextField="NewsTitle" HeaderText="编辑" DataTextFormatString="修改" />
                <asp:CommandField ShowDeleteButton="True" HeaderText="删除" />
            </Columns>
            <RowStyle BackColor="#EFF3FB" />
            <EditRowStyle BackColor="#2461BF" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>

posted @ 2010-05-07 15:59  .小武.  阅读(2869)  评论(0编辑  收藏  举报