I have a gridview which is bounded as
<asp:GridView
runat="server"
ID="gvShipDetails"
AutoGenerateColumns="false"
OnRowDataBound="gvShipDetails_RowDataBound">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Ship name
<br />
<asp:TextBox class="search_textbox" runat="server" BorderStyle="None" Width="100%">
</asp:TextBox>
</HeaderTemplate>
<ItemTemplate>
<%#Eval("VesselName")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The problem is the finally rendered html table td is rendered as
<td> sample vessel name </td>
A lot of spaces inside td.How is this possible.
If I replace this bound code as
<asp:BoundField HeaderText="vessel name" DataField="vesselname" />
Then html is renderd as <td>sample vessel name<td>
Why is it so? I wanted to use headertemplate and i wanted to avoid these trailing spaces. How to do it
Any help will be appreciated
As Naveen suggested Doing
<ItemTemplate><%#Eval("VesselName")%></ItemTemplate>
Solved my issue and the reason for this is unknown for me
Related
Hii I am using a grid with more than 1000 rows (from database). I was using Paging. a new requirement is to remove paging and show only 50 records at first load and then when user scrolls the page down and reaches to bottom of grid, show next 50 records and so on.. I really dont have any idea about it can any one plz help .... I am using VB.net with 4.0 framework.
following is my code to display grid
<%# Page Language="VB" MasterPageFile="~/MasterPage/abc.master" AutoEventWireup="false" CodeFile="TM.aspx.vb" Inherits="TM" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderMain" runat="server" ID="ctn">
<div>
<asp:GridView ID="gvGrid" runat="server" Visible="false" AutoGenerateColumns="False" BorderStyle="Solid" BorderWidth="1px" BorderColor="#6495ED" BackColor="White" HeaderStyle-BackColor="#6495ED">
<AlternatingRowStyle BackColor="#DDEEFF" />
<Columns >
<asp:TemplateField HeaderStyle-Width="10px">
<HeaderTemplate><asp:CheckBox ID="Chk_All_ALert" runat="server" onClick="checkboxAll_click('gvGrid',this.checked,'chk_Alert');"></asp:CheckBox></HeaderTemplate>
<ItemTemplate>
<input type="checkbox" runat="server" id="chk_Alert" value=<%#Eval("UniqueID")%> onclick="CheckUncheck_All('gv_AlertHistory',this.checked,'gvGrid','chk_Alert');"/>
<%--<input type="hidden" id="hdnIDAlert" value=<%#Eval("SchoolID")%> runat="server"/>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Wrap="false">
<HeaderTemplate>Date/Time</HeaderTemplate>
<ItemTemplate><%#DisplayTime(Eval("SentDate"))%></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Email Subject</HeaderTemplate>
<ItemTemplate><%#Eval("Subject")%></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Email Text</HeaderTemplate>
<ItemTemplate><%#GetAlertGridMessage(Eval("Message"))%></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</asp:Content>
you should use 'Jscroll' or follow this example this may be helpful to you
http://aspsnippets.com/Articles/Load-data-while-Scrolling-Page-down-with-jQuery-AJAX-and-ASPNet.aspx
I created with ASP.NET Dynamic Data Entities Web App and ADO.NET Entity Data Model an dynamic application to modify an sql table.
But how can i modify in gridView column width?? The columns are big but the data will be cut.
Table column width screenshot
In *.edmx file the MaxLength is set to 300.
<Property Name="foreign_data" Type="nvarchar" Nullable="false" MaxLength="300" />
The grid view in Lists.aspx looks like:
<asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" EnablePersistedSelection="true"
AllowPaging="True" AllowSorting="True" CssClass="DDGridView"
RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6"
PageSize="15">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DynamicHyperLink runat="server" Action="Edit" Text="Bearbeiten"
/> <asp:LinkButton runat="server" CommandName="Delete" Text="Löschen"
OnClientClick='return confirm("Sind Sie sicher das Sie diesen Datensatz löschen möchten?");'
/> <asp:DynamicHyperLink runat="server" Text="Details" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="DDFooter"/>
<PagerTemplate>
<asp:GridViewPager runat="server" />
</PagerTemplate>
<EmptyDataTemplate>
There are currently no items in this table.
</EmptyDataTemplate>
</asp:GridView>
So how can i control the lenght. By the way, every field is cut after 22 chars! I search the whole solution but no more MaxLength values found. If I set MaxLength Value in gridView it doesen't work.
Ok I solved it. I've modified the field template (text.ascx.cs) from
private const int MAX_DISPLAYLENGTH_IN_LIST = 25;
to an higher value....
Maybe you entered some "maxlength" Attribute cause both of your values are 22 characters Long.
something like this maybe?
<asp:TextBox ID="txtmyValue" MaxLength="10" runat="server" ..../>
Did you got "BoundField"'s so maybe you should replace them with "TemplateField"'s instead so you can control whats going on:
<asp:TemplateField HeaderText="my text value">
<ItemTemplate>
<asp:TextBox ID="txtmyValue" MaxLength="40" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "YOUR_BOUND_ITEM_NAME") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
I have a gridview with a hyperlink:
<asp:GridView ID="gvEmployees" runat="server" AutoGenerateColumns="False"
CssClass="table table-hover table-striped" GridLines="None" >
<Columns>
<asp:TemplateField HeaderText="Name" SortExpression="EmployeName">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
Text='<%# Bind("EmployeName") %>' ></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" SortExpression="EmployeID" Visible="False">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Bind("EmployeID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
However, it should only appear as a hyperlink if the employeeID is that of the logged in employee.
I can do all that, but what I do not know is how to make the hyperlink look like a Label. It's easy to have it not link anywhere, but I do not know how to make it look like a label.
Thanks
I believe if you set Enabled="false" it does. If it does not, then the only way to do that is put both a HyperLink and Label in the cell, and show the link when appropriate, and the label when appropriate, hiding the other one (which can be easily done in RowDataBound event).
Q:
I have a gridview contains a textbox as a template field :
the aspx:
<asp:GridView Width="100%" ID="gv_Evaluation" CssClass="datatable" AllowSorting="True"
runat="server" AutoGenerateColumns="False" AllowPaging="True" GridLines="None"
OnRowDataBound="gv_Evaluation_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="serial">
<ItemTemplate>
<asp:Label ID="lblSerial" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="activity type" DataField="activityType" />
<asp:BoundField HeaderText="weight" DataField="activityWeight" />
<asp:TemplateField HeaderText="evaluation">
<ItemTemplate>
<telerik:RadTextBox ID="txt_evaluateWeights" runat="server" AutoPostBack="True"
OnTextChanged="txt_evaluateWeights_TextChanged"></telerik:RadTextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txt_evaluateWeights" Display="Dynamic" ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle VerticalAlign="Top" CssClass="row" />
</asp:GridView>
the weight column contains the following numbers[50,10,10,10,5,5,10]
What I wanna to do is:
Validate the data entry when the user enters the data in the txt_evaluateWeights Where it must be less than or equal the meeting one in the weight column. I do that in server side. But I wanna to do that client side. I tried to use the compare validator but it doesn't suit my case because each time i compare with a different value, according to the weight column.
You can use the CustomValidator class and set the ClientValidationFunction property to use clientside validation
see MSDN documentation
I'm building a GridView control which encapsulates a child gridview. The child gridview holds a div tag which is displayed when the user selects a row in the parent gridview. However, even though the contents is hidden i.e. the div tag, an extra column is added - how do I get rid of the extra column. In the tutorial it states that by adding a </td></td> and starting a new row <tr> this should happen but it does (I also noticed that the author turned off gridlines so my assumption is that he in fact has this problem also). Here is the gridview, oh and I set the visible state of the itemtemplate to 'true' but then the javascript could (not) find it.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="PublicationID"
DataSourceID="ObjectDataSource1" Width="467px" OnRowDataBound="GridView1_RowDataBound"
Font-Names="Verdana" Font-Size="Small">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="PublicationSelector" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NameAbbrev" HeaderText="Publication Name" SortExpression="NameAbbrev" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:TemplateField HeaderText="Owners">
<ItemTemplate>
<asp:Label ID="Owners" runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:TemplateField>
<ItemTemplate >
</td></tr>
<tr>
<td colspan="7">
<div id="<%# Eval("PublicationID") %>" style="display: none; position: relative">
<asp:GridView ID="GridView2_ABPubs" runat="server" AutoGenerateColumns="false" Width="100%"
Font-Names="Verdana" Font-Size="small">
<Columns>
<asp:BoundField DataField="NameAbbrev" HeaderText="Publication Name" SortExpression="NameAbbrev" />
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Apart from the extra column in the master gridview it works fine.
Just for completeness, here is a to the original article (for some reason it didn't like my <a href> tag so it's copy and paste).
To get rid of the extra column, just set its css style to display: none. You can do this by applying a CssClass to the TemplateField containing the nested grid:
<asp:TemplateField HeaderStyle-CssClass="hidden-column" ItemStyle-CssClass="hidden-column" FooterStyle-CssClass="hidden-column">
Here is the definition of the CssClass I used:
<style type="text/css">
.hidden-column {
display: none;
}
</style>
Note: the markup will still be in the html but at least it won't be visible.
Tested under IE 8.0, Google Chrome 2.0 and Opera 10.0
Update: To eliminate the double border, just put the id and the style on the <tr> instead of the <div>:
<tr id="<%# Eval("PublicationID") %>" style="display: none; position: relative">
<td colspan="7">
<div>
...
... and change the display in the javascript from block to table-row:
div.style.display = "table-row"; // not a div anymore!!
Looks like you have unbalanced tags in your <ItemTemplate>:
<ItemTemplate >
</td></tr> <<---- These look unbalanced
<tr>
<td colspan="7">
<div id="<%# Eval("PublicationID") %>" style="display: none; position: relative">
<asp:GridView ID="GridView2_ABPubs" runat="server" AutoGenerateColumns="false" Width="100%"
Font-Names="Verdana" Font-Size="small">
<Columns>
<asp:BoundField DataField="NameAbbrev" HeaderText="Publication Name" SortExpression="NameAbbrev" />
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
I don't see an opening tag for these tr, td tags:
...
<ItemTemplate >
</td></tr>
...
Just checked and the author of the article seems to have the same issue in the generated source of the page.