I have changed a Grid View from UltraWebGid to ASP.NET Grid View.
The code for ASP.NET Grid View is like this:
<asp:Panel ID="pnlLicenseMaintainHistory" runat="server" CssClass="gridScroll" >
<asp:GridView ID="gridLicenseMaintainHistory" runat="server" AllowPaging="false" AutoGenerateColumns="false"
EmptyDataText="No Records Found" EnableViewState="True" Width="99%" >
<Columns>
<asp:TemplateField HeaderText="Select" >
<ItemTemplate>
<asp:LinkButton runat="server" ID="linkButtonLicenseMaintainHistory" CommandArgument='<%# Eval("licensemaintain_hst_key")%>' Text="Select"
OnClick="lnkLicenseMaintainHistory_Click"></asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="6%" />
</asp:TemplateField>
<asp:BoundField HeaderText="License Type" DataField="license_info" HeaderStyle-CssClass="filterColumn">
<ItemStyle Width="10%" />
</asp:BoundField>
<asp:BoundField HeaderText="License ID" DataField="license_id" HeaderStyle-CssClass="filterColumn">
<ItemStyle Width="10%" />
</asp:BoundField>
<asp:BoundField HeaderText="Issued Date" DataField="issued_dttm" DataFormatString="{0:MM/dd/yyyy}" HeaderStyle-CssClass="filterColumn" HtmlEncode="False">
<ItemStyle Width="10%" />
</asp:BoundField>
<asp:BoundField HeaderText="Effective Beg Date" DataField="effective_begin_dt" DataFormatString="{0:MM/dd/yyyy}" HeaderStyle-CssClass="filterColumn" HtmlEncode="False" >
<ItemStyle Width="10%" />
</asp:BoundField>
<asp:BoundField HeaderText="Effective End Date" DataField="effective_end_dt" DataFormatString="{0:MM/dd/yyyy}" HeaderStyle-CssClass="filterColumn" HtmlEncode="False" >
<ItemStyle Width="10%" />
</asp:BoundField>
<asp:BoundField HeaderText="Status" DataField="license_status" HeaderStyle-CssClass="filterColumn">
<ItemStyle Width="10%" />
</asp:BoundField>
<asp:BoundField HeaderText="Update By" DataField="updated_by" HeaderStyle-CssClass="filterColumn">
<ItemStyle Width="10%" />
</asp:BoundField>
<asp:BoundField HeaderText="Updated Date" DataField="updated_dttm" DataFormatString="{0:MM/dd/yyyy}" HeaderStyle-CssClass="filterColumn" HtmlEncode="False" >
<ItemStyle Width="10%" />
</asp:BoundField>
<asp:BoundField HeaderText="Record Type" DataField="record_type" HeaderStyle-CssClass="filterColumn">
<ItemStyle Width="10%" />
</asp:BoundField>
</Columns>
</asp:GridView>
</asp:Panel>
But when I go to my application the Grid View doesn't show up. What is wrong in my code? Thanks in advance.
You are missing the closing tag for <asp:TemplateField HeaderText="Select">. Had you formatted your markup correctly, you would've noticed that.
Related
<asp:BoundColumn DataField="CreatedDate" ReadOnly="True" HeaderText="CreatedDate"
DataFormatString="{0:dd/MMM/yyyy}">
<ItemStyle Wrap="false" Width="90px" />
</asp:BoundColumn>
<asp:BoundColumn DataField="CreatedByUser" ReadOnly="True" HeaderText="CreatedBy">
<ItemStyle Wrap="false" Width="100px" />
</asp:BoundColumn>
<asp:BoundColumn DataField="Team" ReadOnly="True" HeaderText="AssignedTeam">
<ItemStyle Wrap="false" Width="150px"/>
</asp:BoundColumn>
<asp:BoundColumn DataField="ExpectedDate" ReadOnly="True" HeaderText="ExpectedDate"
DataFormatString="{0:dd/MMM/yyyy HH:mm:ss}">
<ItemStyle Wrap="false" Width="90px" />
</asp:BoundColumn>
<asp:BoundColumn DataField="ClosedDate" ReadOnly="True" HeaderText="ClosedDate">
<ItemStyle Wrap="false" Width="130px" />
</asp:BoundColumn>
<asp:BoundColumn DataField="ClosedByUser" ReadOnly="True" HeaderText="ClosedBy">
<ItemStyle Wrap="false" Width="150px" />
</asp:BoundColumn>
<asp:BoundColumn DataField="CloseReasonDescription" ReadOnly="True" HeaderText="CloseReason">
<ItemStyle Wrap="false" Width="100px" />
</asp:BoundColumn>
<asp:BoundColumn DataField="email" ReadOnly="True" HeaderText="emailContent">
<ItemStyle Width="200px" >
</ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
but my email in the grid view is not dispalying the format. when i debug i could see the content of that column to be having formatting but it does not respect formatting when displaying
added this style to column for which i want to retain the formatting
<style type="text/css">
.formatCommentText
{
word-break:break-all;
word-wrap:break-word;
white-space: pre-wrap;
width: 40%;
}
</style>
<asp:BoundColumn DataField="email" ReadOnly="True" HeaderText="emailContent">
<ItemStyle CssClass="formatCommentText" Width="40%" >
</ItemStyle> </asp:BoundColumn>
I would like to adjust footer template horizontal align as left in grid but, it's not working any one can explain please. this is my code
<asp:GridView ID="Grd_View" ShowFooter="True" runat="server" OnRowEditing="Grd_View_RowEditing" AutoGenerateColumns="False"
DataKeyNames="CustomerCode" CellPadding="4" OnRowCommand="Grd_View_RowCommand" GridLines="None" ShowHeader="True"
AllowPaging="True" AllowSorting="True" CssClass="style2" ForeColor="#333333" OnRowDataBound="Grd_View_RowDataBound"
OnRowDeleting="Grd_View_RowDeleting" >
<FooterStyle BackColor="#555555" ForeColor="White" HorizontalAlign="Center" Font-Bold="True" />
<Columns>
<asp:BoundField DataField="CustomerCode" HeaderText="Customer Code" InsertVisible="False"
ReadOnly="True" SortExpression="CustomerCode" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="CustomerName" HeaderText="Customer Name" SortExpression="CustomerName" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="TellNo" HeaderText="Tell No" SortExpression="TellNo" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="FaxNo" HeaderText="Fax No" SortExpression="FaxNo" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="PIC" HeaderText="Person in Contact" SortExpression="PIC" ItemStyle-HorizontalAlign="Center" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnEdit" runat="server" CommandArgument='<%#Eval("CustomerCode")%>' CommandName="Edit" Text="Edit">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnDelete" runat="server" CommandArgument='<%#Eval("CustomerCode")%>' CommandName="Delete" Text="Delete">
</asp:LinkButton>
</ItemTemplate>
<FooterTemplate> <asp:LinkButton ForeColor="white" ID="btnNew" runat="server" CommandArgument='<%#Eval("CustomerCode")%>' CommandName="New" Text="New">
</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#777777" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#555555" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
Try using the below:
<FooterTemplate>
<asp:LinkButton ForeColor="white" ID="btnNew" runat="server" CommandName="New" Text="New">
</asp:LinkButton>
</FooterTemplate>
<FooterStyle HorizontalAlign="Left" />
The Reason your footer template will always be in right is because you are creating it as the last column in the GridView along with the Delete column.
To solve this you need to create the footer template in the first column or I'll recommend just putting the footer template inside with edit template field in the first column and the delete template field in the second column.
Again, New issue. Please be guided to the image below.
Here's the output (see the image below):
Here's the code of my Gridview in results.aspx
<asp:GridView runat="server" id="GridView1" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" DataKeyNames="ID" BorderStyle="Ridge" BackColor="White" BorderColor="Black" BorderWidth="3px" CellPadding="3" Width="1000px" AllowPaging="True" PageSize="2">
<RowStyle BackColor="White" ForeColor="#003399" HorizontalAlign="Center" VerticalAlign="Middle" />
<Columns>
<asp:boundfield DataField="Time In" HeaderText="Time In" SortExpression="Time In">
<ItemStyle Width="100px" />
</asp:boundfield>
<asp:boundfield DataField="Username" HeaderText="Bar Code No." SortExpression="Username">
</asp:boundfield>
<asp:boundfield DataField="FirstName" HeaderText="First Name" SortExpression="FirstName">
</asp:boundfield>
<asp:boundfield DataField="LastName" HeaderText="Last Name" SortExpression="LastName">
</asp:boundfield>
<asp:boundfield DataField="MiddleName" HeaderText="Middle Name" SortExpression="MiddleName">
</asp:boundfield>
<asp:boundfield DataField="ContactNumber" HeaderText="Contact No." SortExpression="ContactNumber">
</asp:boundfield>
<asp:boundfield DataField="PlateNumber" HeaderText="Plate No." SortExpression="PlateNumber">
</asp:boundfield>
<asp:boundfield DataField="Color" HeaderText="Color" SortExpression="Color">
</asp:boundfield>
<asp:boundfield DataField="Brand" HeaderText="Brand" SortExpression="Brand">
</asp:boundfield>
<asp:boundfield DataField="LiscensedNumber" HeaderText="Liscensed No." SortExpression="LiscensedNumber">
</asp:boundfield>
<asp:templatefield>
<HeaderTemplate>
Image
</HeaderTemplate>
<ItemTemplate>
<img src="data:image/jpg;base64,<%# Eval("Image") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("Image")) : string.Empty %>" alt="image" height="85" width="85" />
</ItemTemplate>
</asp:templatefield>
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle HorizontalAlign="Center" BackColor="#999999" ForeColor="#003399" />
<EmptyDataTemplate>
No data found!
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A0A0A0" Font-Bold="True" ForeColor="#003399" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>
Please help. I don't know the code regarding "Date and Time" thing.
Try removing space in your datafield, as by Rahul R.
It does not matter in the Header Text but in datafield it does.
<asp:boundfield datafield="Your_Date_Column" dataformatstring="{0:MMMM d, yyyy}" htmlencode="false" />
also make sure there are no spaces in datafield name
Sorry for asking here, I solved it.
I convert the column in templatefield then I added this code
Text='<%# DateTime.Now.ToString("dddd<br /> MMMM dd, yyyy<br /> hh:mm tt") %>
:) thanks to all of you.
I'm running into a strange issue. I'm trying to see what checkboxes are selected within the gridview. My code looks like it follows the examples I found on the internet, and works in FF & Chrome, but fails in IE9.
In IE9, the checked property never returns true. I've stepped through the code, and have verified that it's looking at the correct checkbox, but IE will always return false.
Does anyone have any ideas? Below is my markup & codebehind.
<asp:GridView ID="gvParts" runat="server"
AllowSorting="True" AutoGenerateColumns="False"
CellPadding="5" DataKeyNames="Rec_ID" DataSourceID="dsParts"
PageSize="50" Width="100%">
<Columns>
<asp:TemplateField HeaderText="Select">
<HeaderTemplate>
Select
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="75px" />
</asp:TemplateField>
<asp:BoundField DataField="Arcft_Make" HeaderText="Make"
SortExpression="Arcft_Make" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Arcft_Model" HeaderText="Model"
SortExpression="Arcft_Model" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Source_Name"
HeaderText="Source_Name"
SortExpression="Source_Name"
DataFormatString="{0:d}"
HtmlEncode="false">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Part_Number"
HeaderText="Part Number"
SortExpression="Part_Number" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Vendor_Part_Number"
HeaderText="Vendor Number"
SortExpression="Vendor_Part_Number" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Vendor_Name"
HeaderText="Vendor Name"
SortExpression="Vendor_Name" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Descr"
HeaderText="Description"
SortExpression="Descr">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle Width="300px" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Date_Added"
HeaderText="Date_Added"
SortExpression="Date_Added">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Rec_ID"
ReadOnly="True" Visible="False">
<ItemStyle Width="0px" />
</asp:BoundField>
<asp:CommandField ShowEditButton="True" />
</Columns>
<SelectedRowStyle BackColor="#FFFFCC" />
<AlternatingRowStyle BackColor="#CCFFFF" />
</asp:GridView>
`
And
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles btnAdd.Click
Dim Rec_IDs As New List(Of String)
Dim Rec_ID As Int32
Rec_IDs = Session("Rec_IDs")
For Each Row As GridViewRow In gvParts.Rows
If CType(Row.FindControl("chkSelect"), CheckBox).Checked Then
Rec_ID = gvParts.DataKeys(Row.RowIndex).Value
If Not Rec_IDs.Contains(Rec_ID) Then
Rec_IDs.Add(Rec_ID)
End If
CType(Row.FindControl("chkSelect"), CheckBox).Checked = False
End If
Next
Session("Rec_IDs") = Rec_IDs
lblCount.Text = String.Format("You have {0} records selected",
Rec_IDs.Count.ToString)
End Sub
OK, solved. My gridview wasn't inside my form tags. I guess IE didn't like that.
If you click on the 'search' button in the following link
link text
A gridview shows up. I am trying to do something similar within a table whose width is set to auto. My current way is to create the gridview in design view, but however, my gridview does not resize to the table width. I understand that I posed 2 different questions in one.
My current gridview is as such. Defined in 'source' view
<asp:GridView ID="gridView" runat="server"
AutoGenerateColumns="False"
EnableSortingAndPagingCallbacks="True"
AllowPaging="True" DataSourceID="FilesByJobObjectDataSource"
PageSize="5" OnRowCommand="gridView_RowCommand" DataKeyNames="FileID"
HorizontalAlign="Left" >
<Columns>
<asp:BoundField DataField="RID" HeaderText="RID"
ReadOnly="True" ItemStyle-Width="50px" >
<ItemStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="Category" HeaderText="Category"
ReadOnly="True" ItemStyle-Width="100 px" >
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="FileName" HeaderText="Type"
ReadOnly="True" ItemStyle-Width="575 px" >
<ItemStyle Width="575px" />
</asp:BoundField>
<asp:BoundField DataField="FileID" Visible="false" />
<asp:ButtonField Text="X" ButtonType="Button" ItemStyle-Width="20px" >
<ItemStyle Width="20px" />
</asp:ButtonField>
</Columns>
<RowStyle CssClass="RowStyle" />
<EmptyDataRowStyle CssClass="EmptyRowStyle" />
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
</asp:GridView>
</ContentTemplate>
Don't set the column widths....