I want my label "The Top Row" to be positioned near the top row of my gridview as I indicated with yellow below,
I tried absolute positioning the lable but when displayed, there are problems with it. What is the best way to do this ? (float right is working like allign left which is not useful and I have tried display block but couldn't find a way with it too)
This is such a basic issue but can not find a solution
You simply need to add float: left to both the <asp:GridView /> and the <asp:Label />:
HTML Markup:
<asp:GridView ID="GridView1" runat="server" CellPadding="10"
ForeColor="#333333" style="float: left;" AutoGenerateColumns="False">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:ButtonField ButtonType="Button" Text="Info File" />
<asp:ButtonField ButtonType="Button" Text="Get Contact" />
<asp:BoundField DataField="Column0" HeaderText="Column0" />
<asp:BoundField DataField="Column1" HeaderText="Column1" />
<asp:BoundField DataField="Column2" HeaderText="Column2" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:Label ID="TopRowLabel" runat="server" style="float: left;" />
Output:
Perhaps you could try to add the style float: left or something similar to the grid?
Also try to experiment with display: block and the other values for display.
Try using Jquery to find the Header Row and the probably use .Append (to append the element).
If the value of the label/element comes from server then you can set the hidden variable (runat="server") in the code behind and then use Jquery again to set the value of the label (rendered probably as span)
Related
i have currently create a user web control with a dataview in it
currently this is the gridview
<div class="col-md-12">
<asp:GridView id="dtgrid1" runat="server" AutoGenerateColumns="False" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateSelectButton="True" CellPadding="4" ForeColor="#333333" GridLines="Horizontal" AllowPaging="True" width="100%" ShowFooter="True" ShowHeaderWhenEmpty="True" EmptyDataText="No records Found">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" ItemStyle-Width="30" />
<asp:BoundField DataField="Descripcion" HeaderText="Descripcion" ItemStyle-Width="250" />
<asp:BoundField DataField="Monto" HeaderText="Monto" ItemStyle-Width="150" />
<asp:BoundField DataField="Fecha" HeaderText="Fecha" ItemStyle-Width="150" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</div>
that gridview is in a webuser control with other cotrols and divs, everythings show as it should but the gridviews
this is the code on the onload event
If Not Page.IsPostBack Then
dim dgv1datatable as new DataTable
With dgv1datatable
.Columns.Add(New DataColumn("ID", GetType(Integer)))
.Columns.Add(New DataColumn("Descripcion", GetType(String)))
.Columns.Add(New DataColumn("Monto", GetType(Double)))
.Columns.Add(New DataColumn("Fecha", GetType(Date)))
End With
Session("dgv1dt") = dgv1datatable
dtgrid1.DataSource = DirectCast(Session("dgv1dt"), DataTable)
dtgrid1.DataBind()
dtgrid1.Visible = True
End If
but it's now showing the gridview but if i insted place the gridview where the placeholder should be the gridview shows any help please?
EDIT
im going to try and explain better the issue
this is where the gridview should've within a webusercontrol that is in a placeholder
so since it wasn't showing i decided to delete the placeholder and place the gridview in the same place and it did appear
<asp:SqlDataSource ID="SqlDataSource1" runat="server" CacheExpirationPolicy="Sliding"
ConnectionString="<%$ ConnectionStrings:catalog %>"
SelectCommand="SELECT * FROM YourDB"></asp:SqlDataSource>
I have a gridView and two checkboxes that will be used for filtering..
the first checkbox(Accepted), when checked, the gridview will only show data from the database that have the status Accepted.
Here's my gridview and checkbox:
<div style="height: 250px; overflow-x: hidden; overflow-y: scroll;" >
<asp:CheckBox ID="Accepted" runat="server" />
<asp:CheckBox ID="Pending" runat="server" />
<asp:CheckBox ID="Rejected" runat="server" />
<asp:GridView ID="gvtransaction" runat="server" Width="30%" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="5px" DataKeyNames="id" GridLines="Horizontal" OnRowDataBound="gvtransaction_RowDataBound" OnRowCommand="TransactionStatus">
<Columns>
<asp:BoundField DataField="MerchantID" HeaderText="ID" SortExpression="" />
<asp:BoundField DataField="FirstName" HeaderText="Consumer" SortExpression="" />
<asp:BoundField DataField="LastName" HeaderText="Name" SortExpression="" />
<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="" />
<asp:BoundField DataField="CurrencyName" HeaderText="Account Name" SortExpression="" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="" />
<asp:ButtonField ButtonType="Button" CommandName="Accept" HeaderText="Action" ShowHeader="True" Text="Accept" />
<asp:ButtonField ButtonType="Button" CommandName="Reject" HeaderText="Action" ShowHeader="True" Text="Reject" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
How can i do this using javascript.?
thank you...
You can use following properties of gridview 'onrowdatabound and DataKeyNames'.
In DataKeyNames you can give the name of your class variables or properties where you are reading from database through a datareader.
Fire the rowDatabound event of your gridview so that you can check the status
protected void gvtransaction_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
int Status = (int)this.gvtransaction.DataKeys[e.Row.RowIndex].Values[0];
if (Status)
{
.
check status values for Accepted, pending and rejected through if else.
.
.
}
}
You can create 2 Grid views and when one of the check boxes selected bind the associated grid view.
I am using linq to entity i have added the gridview but it's not editing and when i debug it doesn't access the method GridView5_RowUpdating().. here it's the code of the grid view
<asp:GridView ID="GridView5" runat="server" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="4" DataKeyNames="CustomerId"
DataSourceID="SqlDataSource3" ForeColor="#333333" GridLines="None"
onrowupdating="GridView5_RowUpdating">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="CustomerId" HeaderText="CustomerId"
InsertVisible="False" ReadOnly="True" SortExpression="CustomerId" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
I have Required field validator when i am trying to insert manually when i removed the Required field validator can someone tell me what's happening?
Firstly you need to implement the RowEditing event on the gridview to enable editing, MSDN definition:
Occurs when a row's Edit button is clicked, but before
the GridView control enters edit mode.
ASPX:
<asp:GridView
ID="gvCustomers"
runat="server"
OnRowEditing="gvCustomers_RowEditing">
Code behind:
protected void gvCustomers_RowEditing(object sender, GridViewEditEventArgs e)
{
gvCustomers.EditIndex = e.NewEditIndex;
//Re bind the grid view
}
Now if this event is not being fired when you click the Edit link on your grid view it means that there is some validation logic on the page which is preventing a post back.
The best way to get rid of this issue is to set the ValidationGroup attribute, for the validation controls causing trouble(not the gridview):
<div id="insertEmployee">
<asp:TextBox ID="txtName" runat="server" ValidationGroup="Insert" />
<asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txtName" ErrorMessage="Name is required" ValidationGroup="Insert" />
<asp:Button ID="btnAdd" runat="server" Text="Add" ValidationGroup="Insert" />
</div>
I have a GridView in asp that keeps re-sizing itself. Can i in some way fix the size of the GridView so it doesn't do that ? The GridView keeps shrinking itself although the data in it has the same length or is smaller
my asp code:
<asp:GridView ID="Grid" runat="server" AllowPaging="True" PageSize="18" OnPageIndexChanging="Grid_PageIndexChanging"
ForeColor="Black" GridLines="Both" Width="991px" Height="600px" RowStyle-HorizontalAlign="Center"
BackColor="White" BorderColor="#999999" BorderWidth="1px"
AutoGenerateColumns="False" style="margin-left: 9px">
<Columns>
<asp:TemplateField HeaderText="RequestID">
<ItemTemplate>
<a target = "_blank" href="www.danx/default?request=<%# Eval("request")%>"><%# Eval("request")%></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Barcode">
<ItemTemplate>
<a target = "_blank" href="www.danx/default?barcode=<%# Eval("barcode")%>"><%# Eval("barcode")%></a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="adrid" HeaderText="AdrID" SortExpression="AdrID" />
<asp:BoundField DataField="name" HeaderText="Navn" SortExpression="Name" />
<asp:BoundField DataField="street" HeaderText="Vej" SortExpression="Street" />
<asp:BoundField DataField="houseno" HeaderText="Husnr"
SortExpression="HouseNo" />
<asp:BoundField DataField="postal" HeaderText="Postnr"
SortExpression="Postal" />
<asp:BoundField DataField="city" HeaderText="By" SortExpression="City" />
<asp:BoundField DataField="country" HeaderText="Land"
SortExpression="Country" />
<asp:TemplateField HeaderText="Lokation">
<ItemTemplate>
<a target = "_blank" href="https://maps.google.dk/maps?q=<%# Eval("latitude")%>,<%# Eval("longitude")%>"><%# Eval("latitudetxt")%></a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="date" HeaderText="ReceivedDate"
SortExpression="ReceivedDate" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<RowStyle HorizontalAlign="Center"></RowStyle>
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Blue" HorizontalAlign="Center" />
<HeaderStyle BackColor="DarkGray" Font-Bold="True" ForeColor="Black" />
<AlternatingRowStyle BackColor="LightGray" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
Can you help me please?
Since you are using a fixed width (991px) for the gridview, the columns would shrink/adjust as their content grow larger. One thing you could do is give fixed width to those columns you don't want resized (in % or fixed). e.g.
<ItemTemplate>
<a target = "_blank" href="www.danx/default?request=<%# Eval("request")%>"><%# Eval("request")%></a>
</ItemTemplate>
You can also increase the size of the GridView to easily accomodate the columns e.g. Setting it to 100% if the container is greater 991px
is this maybe to do with the data in the cells being too long without spaces.. you can always use
td{word-wrap:break-word;}
or make sure you have spaces.
or even use styles for the columns, which set the widths explicitly
<asp:TemplateField HeaderText="RequestID" HeaderStyle-CssClass="setWidthClass">
<ItemTemplate>...
or even
<asp:TemplateField HeaderText="RequestID" ItemStyle-Width="100">
of course it may be nothing to do with this.
in asp.net, when you have an autogenreated select button on a gridview, is it possible to change the text of it from 'select' to something else of your choosing? If so can anyone point me to an example?
thanks again
Check this similar question:
Changing text of an autogenerated select column of a gridview in asp.net - How?
Example:
<asp:buttonfield buttontype="Button"
commandname="Select"
headertext="Select Customer"
text="SelectText"/>
<asp:GridView ID="gvSearch" runat="server" Visible="False"
OnPageIndexChanging="Grid_Changing" AllowPaging="True" AllowSorting="True"
AutoGenerateSelectButton="True" CellPadding="4" Font-Names="Arial"
Font-Size="XX-Small" ForeColor="#333333" GridLines="None"
onselectedindexchanged="gvSearch_SelectedIndexChanged" PageSize="100">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>