Hello,
I have a DataRepeater with a GridView inside to display some tables from a stored procedure.
Here is my repeater code:
<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>
I have as my repeater binding:
rptResults.DataSource = results.Tables;
rptResults.DataBind();
I have the following for my GridView binding for each table:
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();
}
}
}
The data that comes back could change, since it is a stored procedure, and it will always return an n number of tables.
I would like to try to get my columns to auto size based on the data that is being returned. Right now it squishes most of the data, including date/time data.
I can't seem to figure out how to do this.
Thoughts?