自定义 DataGrid

    <style type="text/css">
.GridViewOverFlow table
{
 width:100%;
 table-layout:fixed; 
 border:2px;
}
.GridViewOverFlow table th
{
 /*align="center" nowrap="nowrap" valign="middle" style="overflow:hidden;"*/
 text-align:center; 
 vertical-align:middle;
 overflow:hidden;
    white-space:nowrap;
 word-break:keep-all;
 text-overflow:ellipsis;
}
.GridViewOverFlow table td
{
 /*width: 160px; float: left; white-space: nowrap; overflow: hidden;
word-break: keep-all;text-overflow: ellipsis;*/
 text-align:center;
 vertical-align:middle;
 white-space:nowrap;
 overflow:hidden;
 word-break:keep-all;
 text-overflow:ellipsis;
}
</style>

 

<asp:DataGrid ID="mygrid" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
        ShowFooter="True" Width="100%" CssClass="GridViewOverFlow">
        <Columns>
            <asp:TemplateColumn>
                <HeaderTemplate>
                    <table style="width: 100%; table-layout: fixed">
                        <caption>
                            图书信息管理
                        </caption>
                        <tr>
                            <th style="width:4em">
                                图书编号</th>
                            <th style="width:4em">
                                ISBN
                            </th>
                            <th style="width:8em">
                                名称
                            </th>
                            <th style="width:4em">
                                分类
                            </th>
                            <th style="width:8em">
                                作者
                            </th>
                            <th style="width:3em">
                                出版社
                            </th>
                            <th style="width:2em">
                                总数
                            </th>
                            <th style="width:3em">
                                可借数
                            </th>
                            <th style="width:4em">
                                被借次数
                            </th>
                            <th style="width:6em">
                                察看详细信息</th>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr align="center" valign="middle">
                        <td>
                            <asp:Label ID="BookIdLabel1" runat="server" Text='<%# Bind("BookId") %>'></asp:Label></td>
                        <td>
                            <asp:Label ID="BookISBNTextBox" runat="server" Text='<%# Bind("BookISBN") %>'></asp:Label></td>
                        <td>
                            <asp:Label ID="BookNameTextBox" runat="server" Text='<%# Bind("BookName") %>'></asp:Label></td>
                        <td>
                            <asp:Label ID="BookSortTextBox" runat="server" Text='<%# Bind("BookSort") %>'></asp:Label></td>
                        <td>
                            <asp:Label ID="BookAuthorTextBox" runat="server" Text='<%# Bind("BookAuthor") %>'></asp:Label></td>
                        <td>
                            <asp:Label ID="BookPCTextBox" runat="server" Text='<%# Bind("BookPC") %>'></asp:Label></td>
                        <td>
                            <asp:Label ID="BookTotalNumTextBox" runat="server" Text='<%# Bind("BookTotalNum") %>'></asp:Label></td>
                        <td>
                            <asp:Label ID="BookUseableNumTextBox" runat="server" Text='<%# Bind("BookUseableNum") %>'></asp:Label></td>
                        <td>
                            <asp:Label ID="BookBorrowedNumTextBox" runat="server" Text='<%# Bind("BookBorrowedNum") %>'></asp:Label></td>
                        <td>
                            <asp:HyperLink ID="NavToDetailWb" runat="server" NavigateUrl="~/Try.aspx" Text="察看更多信息"></asp:HyperLink>
                        </td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    <tr>
                        <td>
                            <table width="100%">
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    </table>
                </FooterTemplate>
            </asp:TemplateColumn>
        </Columns>
    </asp:DataGrid> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WPF自定义DataGrid控件是通过继承现有的DataGrid类,并在其基础上进行修改和扩展来实现的。 自定义DataGrid控件的步骤如下: 1. 创建一个自定义的类,继承自DataGrid。例如,可以命名为CustomDataGrid。 2. 在CustomDataGrid类中,可以添加额外的属性、依赖属性或附加属性,用于自定义DataGrid控件的特定行为或外观。 3. 重写或扩展DataGrid的现有方法、事件和样式,以满足自定义需求。例如,可以重写OnApplyTemplate()方法以应用自定义样式。 4. 根据需要,可以添加新的功能或控件,例如自定义列、单元格、行、排序、筛选、分页等等。 5. 在CustomDataGrid类中,可以通过编写自定义的模板(Template)来修改DataGrid的外观。例如,可以通过修改DataGrid的ControlTemplate来改变整个DataGrid的显示风格。 6. 编写完自定义类后,可以在XAML中使用自定义DataGrid控件,通过添加命名空间引用并将CustomDataGrid作为一个控件使用。可以设置自定义属性、事件和样式,达到期望的效果。 通过自定义DataGrid控件,可以根据实际需求对其进行扩展和修改,以满足特定的业务需求。由于WPF提供了强大的样式、模板和继承机制,因此可以轻松地自定义DataGrid控件,并且可以实现高度的灵活性和可扩展性。这样,可以根据项目的需求和用户的喜好来创建独特的、具有个性化的DataGrid控件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值