Dynamic Columns and Data Sources with .NET Grid View
I'm working on a multipurpose page and instead of adding multiple grids to the same page, we wanted to use one GridView per page, and on page_Init add the required columns and set the appropriate DataSourceID.
So there is something like the following in aspx for that: the codebehind in Page_Init is very simple to add multiple columns and then sets the DataSourceID property of the GridView.
ASPX:
<asp:GridView ID="gvDisplay" runat="server" AutoGenerateColumns="false" CellPadding="5"
width="100%" AllowPaging="true" PageSize="200" DataSourceID="wuProcessLogDataSource">
<RowStyle CssClass="RowStyle" />
<AlternatingRowStyle CssClass="AlternatingRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
</asp:GridView>
<asp:ObjectDataSource id="wuProcessLogDataSource" runat="server" EnablePaging="True"
SelectMethod="GetWUProcessLog" TypeName="Project.Objects.WUProcessLogDal"
SelectCountMethod="GetWUProcessLogTotalRecords">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="w" DefaultValue="0" Name="workunitId" />
</SelectParameters>
</asp:ObjectDataSource>
The object data source is present and works as a first page load trigger without any problem. However, as soon as you click the page button, does the grid disappear from the page? Any ideas?
I would just use DataGrid, but it didn't have the desired dynamic display capabilities for the HyperLinkColumn.
+1
source to share
2 answers