<div style="text-align: left;" dir="ltr" trbidi="on"> <div style="text-align: justify;">There are occasions when one may work with a data source that provides dynamic columns. A stored procedure
that aggregates year-to-date totals, with columns representing the months-to-date, is an example. Towards the beginning of the year, there are only a few columns of data; towards the end of the year, there are many. When displaying data like this in a
DataGrid
or a
GridView
control, it is convenient to set
AutoGenerateColumns
=true, letting ASP.NET create the necessary display columns at runtime. Unfortunately, columns generated this way are not available to the developer through the grid’s
Columns
property, and thus the developer lacks the ability to establish column-based formatting.</div>
And in the code behind use this code in the RowDataBound Event of the Gridview protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells.Count > 0)
{
for (int i = 1; i > e.Row.Cells.Count; i++)
{
e.Row.Cells[i].CssClass = "wordwrap";
}
}
e.Row.Cells[0].CssClass = "sno";
} </div>
Parthasarathi,
Remember to click Mark as Answer on the post that helps to others.
Hunain Hafee...
Member
238 Points
639 Posts
gridview half shown on browser's screen
Nov 04, 2012 08:05 PM|LINK
my griedview is half shown on browser's screen and even it disabled horizontal scroller on screen (browser), why ?
whenever i fill my gridview with many columns than it is half shown and disables scroller too, why ?
<%@ Page Language="C#" MasterPageFile="~/MasterPageAdministration.master" AutoEventWireup="true" CodeFile="adminViewEmplyrFurther.aspx.cs" Inherits="adminViewEmplyrFurther" Title="Untitled Page" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div class="superAdminContent"> <h6>Employer's Personal Information</h6> <asp:GridView ID="GridViewEmplyrPersonalInfo" runat="server" AllowPaging="True" DataSourceID="SqlDataSource1"> <Columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Waleed_orsfinalConnectionString20 %>" DeleteCommand="DELETE FROM [tblPersonalInfo] WHERE [pinfoid] = @pinfoid" InsertCommand="INSERT INTO [tblPersonalInfo] ([bankname], [bankdraftno], [amount], [dod], [doc], [firstname], [lastname], [fathername], [photo], [country], [city], [phoneno], [mobno], [sect], [cnicnum], [domicile], [nationality], [mailingadd], [permanentadd], [companyname], [companyurl], [companyemailadd], [companyadd], [faxnum], [companydescription], [contactperson], [agreedtodec], [userid]) VALUES (@bankname, @bankdraftno, @amount, @dod, @doc, @firstname, @lastname, @fathername, @photo, @country, @city, @phoneno, @mobno, @sect, @cnicnum, @domicile, @nationality, @mailingadd, @permanentadd, @companyname, @companyurl, @companyemailadd, @companyadd, @faxnum, @companydescription, @contactperson, @agreedtodec, @userid)" SelectCommand="SELECT [pinfoid], [bankname], [bankdraftno], [amount], [dod], [doc], [firstname], [lastname], [fathername], [photo], [country], [city], [phoneno], [mobno], [sect], [cnicnum], [domicile], [nationality], [mailingadd], [permanentadd], [companyname], [companyurl], [companyemailadd], [companyadd], [faxnum], [companydescription], [contactperson], [agreedtodec], [userid] FROM [tblPersonalInfo] WHERE [userid] = @userid" UpdateCommand="UPDATE [tblPersonalInfo] SET [bankname] = @bankname, [bankdraftno] = @bankdraftno, [amount] = @amount, [dod] = @dod, [doc] = @doc, [firstname] = @firstname, [lastname] = @lastname, [fathername] = @fathername, [photo] = @photo, [country] = @country, [city] = @city, [phoneno] = @phoneno, [mobno] = @mobno, [sect] = @sect, [cnicnum] = @cnicnum, [domicile] = @domicile, [nationality] = @nationality, [mailingadd] = @mailingadd, [permanentadd] = @permanentadd, [companyname] = @companyname, [companyurl] = @companyurl, [companyemailadd] = @companyemailadd, [companyadd] = @companyadd, [faxnum] = @faxnum, [companydescription] = @companydescription, [contactperson] = @contactperson, [agreedtodec] = @agreedtodec, [userid] = @userid WHERE [pinfoid] = @pinfoid"> <SelectParameters> <asp:QueryStringParameter QueryStringField="userid" Name="userid" Type="Int32" /> </SelectParameters> <DeleteParameters> <asp:Parameter Name="pinfoid" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="bankname" Type="String" /> <asp:Parameter Name="bankdraftno" Type="String" /> <asp:Parameter Name="amount" Type="Int32" /> <asp:Parameter DbType="Date" Name="dod" /> <asp:Parameter Name="doc" Type="String" /> <asp:Parameter Name="firstname" Type="String" /> <asp:Parameter Name="lastname" Type="String" /> <asp:Parameter Name="fathername" Type="String" /> <asp:Parameter Name="photo" Type="String" /> <asp:Parameter Name="country" Type="String" /> <asp:Parameter Name="city" Type="String" /> <asp:Parameter Name="phoneno" Type="String" /> <asp:Parameter Name="mobno" Type="String" /> <asp:Parameter Name="sect" Type="String" /> <asp:Parameter Name="cnicnum" Type="String" /> <asp:Parameter Name="domicile" Type="String" /> <asp:Parameter Name="nationality" Type="String" /> <asp:Parameter Name="mailingadd" Type="String" /> <asp:Parameter Name="permanentadd" Type="String" /> <asp:Parameter Name="companyname" Type="String" /> <asp:Parameter Name="companyurl" Type="String" /> <asp:Parameter Name="companyemailadd" Type="String" /> <asp:Parameter Name="companyadd" Type="String" /> <asp:Parameter Name="faxnum" Type="Int64" /> <asp:Parameter Name="companydescription" Type="String" /> <asp:Parameter Name="contactperson" Type="String" /> <asp:Parameter Name="agreedtodec" Type="Boolean" /> <asp:Parameter Name="userid" Type="Int32" /> <asp:Parameter Name="pinfoid" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="bankname" Type="String" /> <asp:Parameter Name="bankdraftno" Type="String" /> <asp:Parameter Name="amount" Type="Int32" /> <asp:Parameter DbType="Date" Name="dod" /> <asp:Parameter Name="doc" Type="String" /> <asp:Parameter Name="firstname" Type="String" /> <asp:Parameter Name="lastname" Type="String" /> <asp:Parameter Name="fathername" Type="String" /> <asp:Parameter Name="photo" Type="String" /> <asp:Parameter Name="country" Type="String" /> <asp:Parameter Name="city" Type="String" /> <asp:Parameter Name="phoneno" Type="String" /> <asp:Parameter Name="mobno" Type="String" /> <asp:Parameter Name="sect" Type="String" /> <asp:Parameter Name="cnicnum" Type="String" /> <asp:Parameter Name="domicile" Type="String" /> <asp:Parameter Name="nationality" Type="String" /> <asp:Parameter Name="mailingadd" Type="String" /> <asp:Parameter Name="permanentadd" Type="String" /> <asp:Parameter Name="companyname" Type="String" /> <asp:Parameter Name="companyurl" Type="String" /> <asp:Parameter Name="companyemailadd" Type="String" /> <asp:Parameter Name="companyadd" Type="String" /> <asp:Parameter Name="faxnum" Type="Int64" /> <asp:Parameter Name="companydescription" Type="String" /> <asp:Parameter Name="contactperson" Type="String" /> <asp:Parameter Name="agreedtodec" Type="Boolean" /> <asp:Parameter Name="userid" Type="Int32" /> </InsertParameters> </asp:SqlDataSource> </div> </asp:Content>help please ?
anil.india
Contributor
2613 Points
453 Posts
Re: gridview half shown on browser's screen
Nov 05, 2012 08:33 AM|LINK
What style are you applying in this class?
What value you have for overflow: attribute? Have you given Height and Width valu or not? Secondy check if you have any css for Table element also.
.superAdminContent { height:200px; width:200px; overflow:scroll }If you want to have only horizontical scroll bars then
OR
But you need to fix the height/width, then it will work.
codepattern.net/blog ||@AnilAwadh
sarathi125
Star
13599 Points
2691 Posts
Re: gridview half shown on browser's screen
Nov 05, 2012 02:49 PM|LINK
Hi,
<div style="text-align: left;" dir="ltr" trbidi="on"> <div style="text-align: justify;">There are occasions when one may work with a data source that provides dynamic columns. A stored procedure that aggregates year-to-date totals, with columns representing the months-to-date, is an example. Towards the beginning of the year, there are only a few columns of data; towards the end of the year, there are many. When displaying data like this in a or a control, it is convenient to set =true, letting ASP.NET create the necessary display columns at runtime. Unfortunately, columns generated this way are not available to the developer through the grid’s property, and thus the developer lacks the ability to establish column-based formatting.</div>In the aspx page add this style
<style type="text/css">
.wordwrap
{
word-break:break-all;
word-wrap:break-word;
overflow:hidden;
width:150px;
}
.sno
{
word-break:break-all;
word-wrap:break-word;
overflow:hidden;
width:50px;
}
</style>
And in the code behind use this code in the RowDataBound Event of the Gridview
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells.Count > 0)
{
for (int i = 1; i > e.Row.Cells.Count; i++)
{
e.Row.Cells[i].CssClass = "wordwrap";
}
}
e.Row.Cells[0].CssClass = "sno";
} </div>
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: gridview half shown on browser's screen
Nov 07, 2012 08:24 AM|LINK
Try this:
<div style="overflow-x: auto; width:auto"> <asp:GridView ID="GridView1" runat="server" Width="100%"> </asp:GridView> </div>See: http://www.codeproject.com/Tips/385449/Docking-a-GridView-and-add-a-horizontal-scrollbar
Feedback to us
Develop and promote your apps in Windows Store
Hunain Hafee...
Member
238 Points
639 Posts
Re: gridview half shown on browser's screen
Nov 07, 2012 08:13 PM|LINK
thanks guys !