title says it all, I have a gridview, and the second page does not fill the 10 places so it changes height, I need the gridview to stay the same no matter what. I will change to whatever I need to get this done, Ive tried everything I can find online like taking out the height attribute and moving it to css, nothing has worked. I also tried all of the answers here and they did not work either...GridView paging problem!
the CSS i tried is:
.RowStyle {
height: 50px;
}
.AlternateRowStyle {
height: 50px;
}
and the HTML I am using currently is:
<asp:Panel runat="Server" ID="AnonymousMessagePanel">
<br />
<asp:GridView ID="CompletedProjectsGrid" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="ProjectsClosedList"
EnableViewState="False" DataKeyNames="ProjectID" CssClass="mGrid" PagerStyle-CssClass="pgr" RowStyle-CssClass="RowStyle"
AlternatingRowStyle-CssClass="alt" AllowPaging="true" PageSize="10">
<Columns>
<asp:BoundField DataField="ProjectID" HeaderText="ProjectID" HeaderStyle-ForeColor="White" SortExpression="ProjectID" ReadOnly="True" ItemStyle-Width="11%"/>
<asp:BoundField DataField="ProjectName" HeaderText="ProjectName" HeaderStyle-ForeColor="White" SortExpression="ProjectName" ItemStyle-Width="11%"/>
<asp:BoundField DataField="TesterName" HeaderText="TesterName" HeaderStyle-ForeColor="White" SortExpression="TesterName" ItemStyle-Width="11%"/>
<asp:BoundField DataField="ProjectDescription" HeaderText="ProjectDescription" HeaderStyle-ForeColor="White" SortExpression="ProjectDescription" ItemStyle-Width="11%"/>
<asp:BoundField DataField="Platform" HeaderText="Platform" HeaderStyle-ForeColor="White" SortExpression="Platform" ItemStyle-Width="11%"/>
<asp:BoundField DataField="DueDate" HeaderText="DueDate" HeaderStyle-ForeColor="White" SortExpression="DueDate" dataformatstring="{0:M/dd/yyyy}" ItemStyle-Width="11%"/>
<asp:BoundField DataField="DateAssigned" HeaderText="DateAssigned" HeaderStyle-ForeColor="White" SortExpression="DateAssigned" dataformatstring="{0:M/dd/yyyy}" ItemStyle-Width="11%"/>
<asp:BoundField DataField="DocumentName" HeaderText="DocumentName" HeaderStyle-ForeColor="White" SortExpression="DocumentName" ItemStyle-Width="11%"/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="ProjectsClosedList" runat="server"
ConnectionString="<%$ ConnectionStrings:ProjectsAndTasksTestConnectionString %>"
SelectCommand="SELECT [ProjectID], [ProjectName], [TesterName], [ProjectDescription], [Platform], [DueDate], [DateAssigned], [DocumentName] FROM [Projects] WHERE ([DateCompleted] IS NULL)">
</asp:SqlDataSource>
</asp:Panel>
Note: all of these ways do actually run and work, they just all change height of the gridview when there is only 2/10 on the last page, and I need it the same height no matter what is in the page
If this is not the best way to achieve this, I am open to better options
use box-sizing
.RowStyle,.AlternateRowStyle{
box-sizing: border-box
}
or just
* { box-sizing: border-box }
you can have a look at max-height too
Try to remove your RowStyle-CssClass="RowStyle and do this and see if it works:
<asp:BoundField DataField="ProjectID" HeaderText="ProjectID" HeaderStyle-ForeColor="White" SortExpression="ProjectID" ReadOnly="True">
<ItemStyle CssClass="RowStyle"></ItemStyle>
</asp:BoundField>
Somehow I feel some of your other styles are influencing the height.
Or try following:
.RowStyle
{
height: 50px !important;
}
.AlternateRowStyle
{
height: 50px !important;
}
Related
I have a aspGridView Control. I am only using it to display information and it does not allow the user to filter. I would like to preset the information where it displays it using a descending sort on the column read_date. Can I do this from the controllers settings?
<asp:GridView AllowPaging="true" runat="server" ID="gridRead" AutoGenerateColumns='false' BorderStyle="None" GridLines="None" HorizontalAlign="Center" Width="200px" PageSize="12" >
<PagerSettings Visible="false" />
<Columns>
<asp:BoundField
HeaderText="Date"
HeaderStyle-HorizontalAlign="Left"
DataField="read_date"
Visible="true"
DataFormatString="{0:d}"
ItemStyle-HorizontalAlign="Left"
HeaderStyle-ForeColor="#004C7E"
HeaderStyle-Font-Underline="true"
ItemStyle-ForeColor="#004C7E"
ItemStyle-Font-Size="Medium"
/>
<asp:BoundField
HeaderText="Reading"
HeaderStyle-HorizontalAlign="Left"
DataField="reading"
Visible="true"
DataFormatString="{0:C}"
ItemStyle-HorizontalAlign="Left"
HeaderStyle-ForeColor="#004C7E"
HeaderStyle-Font-Underline="true"
ItemStyle-ForeColor="#004C7E"
ItemStyle-Font-Size="Medium"
ItemStyle-CssClass="datagridStyle"
/>
So I just want to display the grid with read_date descending. I am binding a DataSet to this grid. Thanks
Set the "order by" command in your stored procedure.
I want to edit and update gridview rows on mouse click event. If the user clicks on a row it should become editable and when he again clicks on the same row it should become uneditable and the changes should be saved.
my gridview looks like:-
<asp:GridView ID="grdexcelsheet" runat="server" AllowPaging="True"
AutoGenerateColumns="False" RowStyle-HorizontalAlign="Left" HorizontalAlign="Center"
onpageindexchanging="grdexcelsheet_PageIndexChanging"
Width = "100%" Height = "100%" Font-Size="Small">
<PagerSettings Position="Bottom" Mode="NextPreviousFirstLast" FirstPageText="First"
LastPageText="Last" NextPageText="Next" PreviousPageText="Prev" PageButtonCount="5" />
<Columns>
<asp:BoundField DataField="SrNo" HeaderText="SrNo" ReadOnly="true" />
<asp:TemplateField HeaderText="CustomerFieldName">
<ItemTemplate>
<asp:Label ID="Label4" Runat="server" Text='<%# Bind("CustomerFieldName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("CustomerFieldName") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CompanyFieldName" HeaderText="CompanyFieldName" ReadOnly="true" />
<asp:BoundField DataField="Usage" HeaderText="Usage" ReadOnly="true" />
</Columns>
</asp:GridView>
There are many ways to do this. You can use AJAX Control Toolkit Modal Popup Extender for updating your grid. Also, you can make use Update Panel from the same toolkit.
If you are willing to use third party controls...please use this which will be very to use
http://obout.com/grid/grid_commands.aspx...
I have grid view and there is a template field in it and i want to get the selected row's index by clicking on button i cant change the field type cause i want to change the visibale attribute in my behind code manually.
Here is my code:
<asp:GridView ID="gvService" runat="server" BackColor="White" AutoGenerateColumns="False"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" DataKeyNames="Service_Id, UserId">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" HeaderStyle-BackColor="Gray">
<HeaderStyle BackColor="Gray"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="L_Name" HeaderText="LastName" SortExpression="L_Name"
HeaderStyle-BackColor="Gray">
<HeaderStyle BackColor="Gray"></HeaderStyle>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="bttCost" runat="server" Text="Cost" OnCommand="Cmd_Pay" Visible='<%# IsNotPaid((Decimal)Eval("Cost")) %>' />
</ItemTemplate>
</asp:TemplateField>
and my behind code:
int rowIndex = gvService.SelectedIndex;
HFServiceID.Value = (string)gvService.DataKeys[rowIndex]["Service_Id"];
HFUserID.Value = (string)gvService.DataKeys[rowIndex]["UserId"];
To get the row index the button that was clicked belongs to, add this in your onclick event.
var rowIndex = ((GridViewRow)((Control)sender).NamingContainer).RowIndex;
HTML
<asp:GridView ID="GridView1" runat="server" GridLines="Vertical" Width="825px" AutoGenerateColumns="False"
DataSourceID="LinqDataSource1">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" ReadOnly="True"
SortExpression="Title" />
<asp:BoundField DataField="Body" HeaderText="Body" ReadOnly="True" ItemStyleWidth="1"
SortExpression="Body"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="DataClassesDataContext"
Select="new (Title, Body)" TableName="PrivateMessages">
</asp:LinqDataSource>
Code
GridView1.Columns[1].ItemStyle.Width = 1;
i would like Fixed Columns[1].width=1 ; While Body containing 100 words;
This Code Does Not Change Width Gridview?
It's not necessary to change the GridView with drag and drop. You have to just select its edges and you can change it.
I am using checkboxs in a GridView. I need to determine the value in the cell in the 2nd column, if a checkbox has been checked.
I am using C# 2008 and ASP.net
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="False" CellPadding="4" GridLines="None" Width="100%" AllowPaging="True" PageSize="20"
onpageindexchanging="gvOrders_PageIndexChanging" ForeColor="#333333">
<Columns>
<asp:TemplateField HeaderText="VerifiedComplete" >
<ItemTemplate>
<asp:CheckBox ID="cbPOID" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PurchaseOrderID" HeaderText="PurchaseOrderID" HtmlEncode="False" ></asp:BoundField>
<asp:BoundField DataField="VENDOR_ID" HeaderText="Vendor ID"></asp:BoundField>
<asp:BoundField DataField="VENDOR_NAME" HeaderText="Vendor Name"></asp:BoundField>
<asp:BoundField DataField="ITEM_DESC" HeaderText="Item Desc"></asp:BoundField>
<asp:BoundField DataField="SYS_DATE" HeaderText="System Date"></asp:BoundField>
</Columns>
<FooterStyle CssClass="GridFooter" BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle CssClass="GridPager" ForeColor="#333333" BackColor="#FFCC66" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle CssClass="GridHeader" BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle CssClass="GridItem" BackColor="#FFFBD6" ForeColor="#333333" />
<AlternatingRowStyle CssClass="GridAltItem" BackColor="White" />
</asp:GridView>
protected void btnDisable_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in gvOrders.Rows)
{
if (((CheckBox)gvr.FindControl("cbPOID")).Checked == true)
{
string strPrimaryid = gvr.Cells[2].ToString();
}
}
}
Another way to do this, to avoid accessing the cells of the GridView by index, is to convert the desired BoundField to a TemplateField in the designer. Then use the FindControl method to get the text value in that cell. By default, the designer will give the Label control of the new TemplateField a name like "Label1."
I would add some pictures to show the designer part, if that process were easier. At any rate, the aspx would change like so, which you could do manually too:
<asp:BoundField DataField="PurchaseOrderID" ...</asp:BoundField>
becomes
<asp:TemplateField HeaderText="PurchaseOrderID">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("PurchaseOrderID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PurchaseOrderID") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
Then you would make this simple code change:
string strPrimaryid = gvr.FindControl("Label1").Text;
However, I think a better way to do this is by utilizing the DataKeys features of the GridView control. The first step would be to set the DataKeyNames property of your GridView:
<asp:GridView ID="gvOrders" runat="server" DataKeyNames="PurchaseOrderID" ...>
Then, assuming your PurchaseOrderID column is of type int, you would change that same line to be:
int primaryid = (int)gvOrders.DataKeys[gvr.RowIndex].Value;