【发布时间】:2012-04-12 22:41:17
【问题描述】:
我有一个内部带有 GridView 的 DataRepeater,用于显示存储过程中的一些表。
这是我的中继器代码:
<asp:Repeater ID="rptResults" runat="server" OnItemDataBound="rptResults_ItemDataBound">
<ItemTemplate>
<div style="width: 1100px; overflow: scroll;">
<asp:GridView ID="gvResults" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan"
BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None">
<FooterStyle BackColor="Tan" Wrap="false" />
<RowStyle Wrap="false" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center"
Wrap="false" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" Wrap="false" />
<HeaderStyle BackColor="Tan" Font-Bold="True" Wrap="false" />
<AlternatingRowStyle BackColor="PaleGoldenrod" Wrap="false" />
</asp:GridView>
<asp:Label runat="server" ID="lblNoRecords" Visible="false"></asp:Label>
</div>
<br />
</ItemTemplate>
</asp:Repeater>
我有我的转发器绑定:
rptResults.DataSource = results.Tables;
rptResults.DataBind();
我对每个表的 GridView 绑定都有以下内容:
protected void rptResults_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var o = e.Item.DataItem as DataTable;
if (o.Rows.Count == 0)
{
var lblNoRecords = (Label) e.Item.FindControl("lblNoRecords");
lblNoRecords.Text = "No Records";
lblNoRecords.Visible = true;
}
else
{
var gv = (GridView)e.Item.FindControl("gvResults");
gv.DataSource = o;
gv.DataBind();
}
}
}
返回的数据可能会改变,因为它是一个存储过程,它总是会返回 n 个表。
我想尝试根据返回的数据使我的列自动调整大小。现在它压缩了大部分数据,包括日期/时间数据。
我似乎不知道该怎么做。
想法?
【问题讨论】: