asp:Gridview annoyance How to display grid -
i'm laying out template web pages rather large web site , many pages using gridview control. will, of course, binding grid data source. right now, lay out template pages, want empty grid display -- need see column headers , empty row.
sadly, control seems want remain invisible unless it's bound datasource. again, going happen eventually,. right now, i'm trying lay out large number of pages end-user approval need frickin' empty grid show on page should be. in fact, database we'll pulling data under development , subject change, binding data right imho waste of time. want template bunch of pages!
all of stackoverflow hits when searching topic deal grids bound data source -- no me in situation. i'm trying below. i'm attempting possible control?
<asp:gridview id="grdreportlist" runat="server" allowpaging="true" allowsorting="true" autogeneratecolumns="false"> <columns> <asp:boundfield datafield="name" headertext="name" readonly="true" sortexpression="name" /> <asp:boundfield datafield="description" headertext="description" sortexpression="description" /> <asp:boundfield datafield="type" headertext="type" sortexpression="type" /> <asp:boundfield datafield="inactive" headertext="inactive" sortexpression="inactive" /> </columns> </asp:gridview>
this should help: gridview.emptydatatemplate
edit: noticed these gridview control properties not set
showheader=true (this default) showfooter=true (set if want footer) showheaderwhenempty=true ( ahaaaaa!)
edit: unbound, header gridview example:
<asp:gridview id="gridview1" runat="server" datasourceid="sqldatasource1" showfooter="true" showheaderwhenempty="true" autogeneratecolumns="false"> <columns> <asp:boundfield datafield="header a" headertext="header a" readonly="true" sortexpression="header a"></asp:boundfield> <asp:boundfield datafield="header b" headertext="header b" readonly="true" sortexpression="header b" dataformatstring="{0:f2}"></asp:boundfield> <asp:boundfield datafield="header c" headertext="header c" readonly="true" sortexpression="header c"></asp:boundfield> <asp:boundfield datafield="header d" headertext="header d" readonly="true" sortexpression="header d" dataformatstring="{0:mm/dd/yyyy}"></asp:boundfield> </columns> </asp:gridview> <asp:sqldatasource id="sqldatasource1" runat="server" selectcommand="select null [header a], 1234 [header b],'c' [header c], cast('1/1/2014' datetime) [header d]" connectionstring='<%$ connectionstrings:cmsconnectionstring %>'> </asp:sqldatasource>
gridview requires datasource, if datasource points nothing. above has connection string valid database, pulls data strictly select statement (note lack of from
clause), provides both header text , row of fake data.
as can see, i'm returning few type of values , formatted in bound field controls. but, aware, if refresh grid, , autogeneratecolumns enabled, lose formatting gridview replace fields. once have grid populated header , data like, disable autogeneratecolumns option in gridview context menu before formatting.
modify necessary populate grid. wash, rinse, repeat grids.
this have been local datasource in app_data directory. you'd need rapid prototyping trying do.
Comments
Post a Comment