It is an asp.net web application with following specifications:
Wndows Xp o/s, IIS 5.1, asp.net frame work is 1.1, VB is server side script, SQL Server 2000 Enterprise edition.

An asp.net datagrid control is dynamicaly populated with sql server 2K database table data by VB Script. The page numbers are properly displayed in local system. But on real remote web server, the page numbers are displayed in a single cell and it's colspan had been set as 1 instead of 10 which is the max. column counts in the grid. Hence the width of the first column in the grid is growing upto the no. of pages are grwoing.

How to solve the problem?

Please assit me at earleast if anybody has solution!

Early thanks,

Regards,
Prasanna V.

Dani AI

Generated

Quick diagnosis and concrete fixes (short version)

The DataGrid’s pager is rendered as a single table row containing one cell that must span the grid’s visible columns; when that colspan is wrong the pager appears as a single narrow cell and forces the first column to expand. (codemag.com)

Two likely causes (and what to do)

  • Column-generation mismatch: is right that your Columns block only contains one TemplateColumn. By default the DataGrid will auto-generate columns unless you set AutoGenerateColumns="False", so you must either declare all columns or explicitly turn off auto-generation to get predictable column counts. (flylib.com)

  • An immediate bug in the posted server code: do not call Dispose() (or otherwise destroy the control) before binding. ASP.NET owns control lifecycle and calling Dispose manually can leave a control in an unusable state and change what gets rendered at runtime — remove the Dispose() / DataSource=null calls and just set the DataSource then DataBind(). (This is the simplest fix and the most likely cause of the remote-server vs local difference.) (stackoverflow.com)

Fallback / safety fix (adjust pager colspan at PreRender)

If you cannot immediately change the binding sequence, correct the pager cell’s colspan in PreRender so it spans the actual column count:

Protected Sub dgdBooksOrderedList_PreRender(sender As Object, e As EventArgs)
  Dim tbl As Table = CType(dgdBooksOrderedList.Controls(0), Table)
  Dim pagerRow As TableRow = tbl.Rows(tbl.Rows.Count - 1)
  pagerRow.Cells(0).Attributes("colspan") = tbl.Rows(1).Cells.Count.ToString()
End Sub

This approach is a pragmatic patch; the real fix is to remove the premature Dispose() and decide explicitly whether AutoGenerateColumns should be true or false. If the problem persists, inspect the rendered HTML (view-source) on the remote server to confirm column count and pager markup, and verify the remote IIS/ASP.NET version matches your local environment. (jwcooney.com)

Recommended Answers

All 3 Replies

please provide some code, reason can be anything..

please provide some code, reason can be anything..

Hello serkan sendure,

Thanks for your concern.

The HTML code part is below.

<div id="tBooksOrderedList" style="BORDER-RIGHT: #ff8080 1px solid; 
	TABLE-LAYOUT: fixed; BORDER-TOP: #ff8080 1px solid; 
	VISIBILITY: visible; OVERFLOW: auto; BORDER-LEFT: #ff8080 1px solid; 
	WIDTH: 990px; BORDER-BOTTOM: #ff8080 1px solid; 
	BORDER-COLLAPSE: separate; HEIGHT: 500px">
	
	<asp:datagrid id="dgdBooksOrderedList" runat="server" 
		BorderColor="Black" PageSize="7" AllowPaging="True"
		BorderStyle="Solid" CellPadding="5">
		
		<SelectedItemStyle BackColor="#FF0066"></SelectedItemStyle>
		<AlternatingItemStyle CssClass="udsGridAlternateItem"></AlternatingItemStyle>
		<ItemStyle Font-Size="XX-Small" Font-Names="Verdana" 
			HorizontalAlign="Justify" VerticalAlign="Middle"></ItemStyle>
		<HeaderStyle HorizontalAlign="Center" CssClass="udsGridHeader" 
			VerticalAlign="Middle" BackColor="#FFE0C0"></HeaderStyle>
		
		<Columns>
			<asp:TemplateColumn HeaderText="Sl. No.">
				<ItemTemplate>
					<asp:Label ID="lblSlNo_T" runat="server" 
						Text='<%# dgdBooksOrderedList.Items.Count +1 %>' 
						CssClass=udsGridItem >
					</asp:Label>
				</ItemTemplate>
			</asp:TemplateColumn>
		</Columns>
		<PagerStyle Position="TopAndBottom" Mode="NumericPages"></PagerStyle>
	</asp:datagrid>
</div>

The server side VB Script is below:

oleDBCon.ConnectionString = strCon
oleDBCon.Open()

strQry = "Select * From tabTableName"

oleDBCMD.Connection = oleDBCon
oleDBCMD.CommandText = strQry
oleDBAdr = New OleDbDataAdapter(strQry, strCon)
oleDBAdr.Fill(dsBooksReport, "tabBooksReportsT")

 dgdBooksOrderedList.DataSource = Nothing
 dgdBooksOrderedList.Dispose()

 dgdBooksOrderedList.DataSource = dsBooksReport.Tables(0) 
 dgdBooksOrderedList.DataBind()
 dgdBooksOrderedList.Visible = True

My words:

The output comes properly in datagrid. But the page numbers are displayed winthin a single cell of data gride. Hence the first column width is growing upto the no. of pages.

Please assist.

Thanks,

Regards,
Prasanna V

ok as far as i understood you are complaining about having a single cell in your grid, and i think the reason is obvious : you have only one column in your columns collection in your datagrid. to have as many columns as you want, you have to add other templateColumns in your columns section of your datagrid. or you can basically remove all these and set autogeneratecolumns property of the datagrid to true.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.