I am having difficulties hiding the sorting arrows on a column header that is not sortable.
I clearly define my sortable columns in the HeaderTemplate sections, and non sortable columns in the ItemTemplate, yet the sorting arrows still appears for the second TemplateField defined below. What am i Missing?
<asp:GridView ID="gvBeneficiary" runat="server" Width="100%" AllowPaging="True" CssClass="gridheader"
EmptyDataText=""
AutoGenerateColumns="False" PageSize="10"
OnPageIndexChanging="gvBeneficiary_PageIndexChanging" OnRowCommand="gvBeneficiary_RowCommand"
OnRowDataBound="gvBeneficiary_RowDataBound" HeaderStyle-CssClass="lhs">
<Columns>
<asp:TemplateField HeaderStyle-CssClass="lhs">
<HeaderTemplate>
<asp:LinkButton ID="lnkFullName" Text="Full Name"
CommandName="Sort" CommandArgument="FullName" runat="server"></asp:LinkButton>
</HeaderTemplate>
<ItemTemplate>
<%#Eval("FullName") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CommandName="EditClick" CommandArgument='<%#Eval("RecipientID") %>'
Text="Edit">
</asp:LinkButton>
<asp:LinkButton ID="lnkDelete" runat="server" CommandName="DeleteClick" CommandArgument='<%#Eval("RecipientID") %>'
Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
What do u mean by defining non sortable columns in the ItemTemplate ?
Specify Allowsorting =true for the grid asd sort expression for respective columns which u want sorting to be enabled.
<asp:GridView AllowSorting="true"......../> and
<asp:TemplateField.............. SortExpression ="Full Name">
And don't specify the sort expression for columns u don't need sorting.
I think this is enough for sorting specified columns.
Is there a reason you can't use the default sorting ability in the gridview? If you can, apply the "arrows" CSS to all hyperlinks in a table header cell
.gvclass th a {background-image...}
That way all headers with a SortExpression will have those CSS properties and all non-sortable headers will not (as no hyperlink will be generated in those cells).
If you just want to disable sorting for a specific column in an event, normally it should work to set the GridViewColumn's SortExpression to null:
gvBeneficiary.Columns[0].SortExpression = null;
I have done this using listview.Please try it with Gridview
my html code is
<asp:ListView ID="lst_Area" runat="server" ItemPlaceholderID="tr" OnItemDataBound="lst_Area_ItemDataBound">
<LayoutTemplate>
<table cellspacing="0">
<tr class="hdrRowColor1">
<td width="35px" align="left">
S.No
</td>
<td align="left" width="400px">
<asp:LinkButton ID="lnk_Name" runat="server" CommandArgument="tblAreaNew.AreaName"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Name</asp:LinkButton>
<asp:Image ID="img_lnk_Name" Visible="false" runat="server" />
</td>
<td align="left" width="250px">
<asp:LinkButton ID="lnk_Location" runat="server" CommandArgument="tblAreaNew.Locationid"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Location</asp:LinkButton>
<asp:Image ID="img_lnk_Location" Visible="false" runat="server" />
</td>
<td align="left" width="175px">
<asp:LinkButton ID="lnk_CreatedBy" runat="server" CommandArgument="v.FirstName" ValidationGroup="vgSearch"
OnClick="lnk_Sort">Created By</asp:LinkButton>
<asp:Image ID="img_lnk_CreatedBy" Visible="false" runat="server" />
</td>
<td align="left" width="120px">
<asp:LinkButton ID="lnk_CreatedOn" runat="server" CommandArgument="tblAreaNew.createddate"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Created On</asp:LinkButton>
<asp:Image ID="img_lnk_CreatedOn" Visible="false" runat="server" />
</td>
<td align="left" width="175px">
<%--<asp:LinkButton ID="lnkCreatedDate" runat="server" CommandArgument="tblUserActivities.CreatedDate"
OnClick="lnk_Sort">Created Date</asp:LinkButton>--%>
<asp:LinkButton ID="lnk_LastModfiedBy" runat="server" CommandArgument="v.FirstName"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Last Modified By</asp:LinkButton>
<asp:Image ID="img_lnk_LastModfiedBy" Visible="false" runat="server" />
</td>
<td align="left" width="120px">
<asp:LinkButton ID="lnk_LastModfiedOn" runat="server" CommandArgument="tblAreaNew.ModifiedDate"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Last Modified On</asp:LinkButton>
<asp:Image ID="img_lnk_LastModfiedOn" Visible="false" runat="server" />
</td>
<td align="center" width="50px">
<asp:LinkButton ID="lnk_Status" runat="server" CommandArgument="tblAreaNew.isactive"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Status</asp:LinkButton>
<asp:Image ID="img_lnk_Status" Visible="false" runat="server" />
</td>
<td align="center" width="50px" style="border-right: 1px solid #6398cc;">
Activity
<%-- <div style="width: 50px; float: right;">
</div>--%>
</td>
</tr>
<tr id="tr" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td align="left" valign="middle">
<%# Container.DataItemIndex+1 %>.
</td>
<td align="left">
<asp:Label ID="lblAreaID" runat="server" Text='<%# Eval("Areaid")%>' Visible="false"></asp:Label>
<%# Eval("AreaName")%>
</td>
<td align="left">
<%# Eval("Location")%>
</td>
<td align="left">
<%# Eval("CreatedBy")%>
</td>
<td align="left">
<%# Convert.ToDateTime(Eval("CreatedDate")).ToString("MMM, dd yyyy")%>
</td>
<td align="left">
<%# Eval("ModifiedBy")%>
</td>
<td align="left">
<%# Convert.ToDateTime(Eval("ModifiedDate")).ToString("MMM, dd yyyy")%>
</td>
<td align="center">
<asp:Label ID="lblLocationIsActive" runat="server" Style="display: none;" Text='<%# Eval("LocationIsActive")%>'></asp:Label>
<asp:Label ID="lbl_Status" runat="server" Style="display: none;" Text='<%# Eval("IsActive")%>'></asp:Label>
<asp:ImageButton ID="imgbtnStatus" runat="server" CommandArgument='<%# Eval("Areaid") %>'
OnClick="imgbtnStatus_Onclick" />
</td>
<td class="last" align="center">
<asp:Label ID="lblAreaName" runat="server" Style="display: none;" Text='<%# Eval("AreaName")%>'></asp:Label>
<asp:ImageButton ID="imgbtnEdit" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/edit.png"
ToolTip="Edit Details" CommandArgument='<%# Eval("AreaId") %>' OnClick="imgbtnEdit_OnClick" />
<asp:ImageButton ID="imgbtnDelete" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/delete.png"
ToolTip="Delete" CommandArgument='<%# Eval("AreaId") %>' Visible="false" OnClientClick="return confirm('Are you sure you want to delete the location?');"
OnClick="imgbtnDelete_OnClick" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
And my code behind code is
protected void lnk_Sort(object sender, EventArgs e)
{
LinkButton lnk = (LinkButton)sender;
string arg = lnk.CommandArgument.ToString();
ViewState["sortCol"] = arg;
GetSortDirection();
BindData(ViewState["sortCol"].ToString(), ViewState["sortDir"].ToString(), Convert.ToInt32(ViewState["nmbr"]), Pager.PageSize);
string name = lnk.ID;
Image img = (Image)(lst_Area.FindControl("img_" + name));
if (img != null)
{
SetSortOrderImage(img, ViewState["sortDir"].ToString());
}
}
private void SetSortOrderImage(Image image, String sortorder)
{
if (sortorder == "asc")
{
image.Visible = true;
image.ImageUrl = "../App_Themes/ThemeNew2/images/up.png";
}
else if (sortorder == "Desc")
{
image.Visible = true;
image.ImageUrl = "../App_Themes/ThemeNew2/images/down.png";
}
}
/// <summary>
/// this method get the sort direction
/// </summary>
private void GetSortDirection()
{
if (Convert.ToString(ViewState["sortDir"]) == "Desc")
{
ViewState["sortDir"] = "asc";
}
else
{
ViewState["sortDir"] = "Desc";
}
}
Hope this will work for you.one this more i would like to let you know the inbuilt sorting and paging are slower for gridview as compare to custom paging and sorting.
Related
I was using a simple html img with jQuery to show the nested table and binding the repeater on itemdatabound. Problem is, this was very expensive by getting all sub items from items in the list at the same time. So I decided it's better when i click the collapse image to show the nested table I should bind the repeater in there.
For this I use imagebutton and command argument to get the ID and use update panel to stop postback from button, but the repeater won't update?
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="rptInventarioLocalizacoes_ItemCommand">
<HeaderTemplate>
<table id="tblInventarioLocalizacoes" class="table table-bordered table-striped dataTable text-center">
<thead class="thead-dark">
<tr>
<th></th>
<th>Nª</th>
<th>Localização</th>
<th>Etq. Por Inventariar</th>
<th>Etq. Inventariadas</th>
<th>Precisão</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:ImageButton ID="ibtnCollapse" runat="server" Style="cursor: pointer" ImageUrl="../../Images/Collapse/plus.png" Width="20" CommandName="BindEtiquetas" CommandArgument='<%# Eval("Localizacao") %>' />
<asp:Panel ID="pnlInventarioEtiquetas" runat="server" Style="display: none">
<asp:UpdatePanel runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ibtnCollapse" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Repeater ID="rptLocalizacoesEtiquetas" runat="server">
<HeaderTemplate>
<table id="tblLocalizacoesEtiquetas" class="nestedtable table table-bordered table-striped dataTable">
<thead class="thead-dark">
<tr>
<th>#</th>
<th>Etiqueta</th>
<th>Validar</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblRowIndex" runat="server" Text='<%# (((RepeaterItem)Container).ItemIndex + 1) %>' />
</td>
<td>
<asp:Label ID="lblEtiqueta" runat="server" Text='<%# Eval("Etiqueta") %>' />
</td>
<td>
<asp:CheckBox ID="chkEtiqueta" runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
<asp:Button ID="btnAddEtiqueta" runat="server" CssClass="btn btn-default" Text="Adicionar Etiqueta" BackColor="#020023" ForeColor="White" Font-Bold="true" />
<asp:Button ID="btnInventariar" runat="server" CssClass="btn btn-default" Text="Inventariar Etiquetas" BackColor="#020023" ForeColor="White" Font-Bold="true" />
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</td>
<td>
<asp:Label ID="lblRowIndex" runat="server" Text='<%# (((RepeaterItem)Container).ItemIndex + 1) %>' />
<asp:Label ID="lblIdlocalizacao" runat="server" Text='<%# Eval("IdInventarioLocalizacao") %>' Style="display: none" />
</td>
<td>
<asp:Label ID="lblLocalizacao" runat="server" Text='<%# Eval("Localizacao") %>' />
</td>
<td>
<asp:Label ID="lblEtiquetasPorInventariar" runat="server" Text='<%# Eval("EtiquetasPorInventariar") %>' />
</td>
<td>
<asp:Label ID="lblEtiquetasInventariadas" runat="server" Text='<%# Eval("EtiquetasInventariadas") %>' />
</td>
<td>
<asp:Label ID="lblPrecisao" runat="server" Text='<%# Eval("Precisao") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
when the html table is exported to excel from asp.net the table is displayed but the content inside the table is not displayed below is my code.
protected void btnExportToExcel_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
lblCategorystatusReportHeader.Visible = true;
Response.AddHeader("content-disposition",
"attachment;filename=StatusReport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
//Panel preOrderPanel = (Panel)rpt1.FindControl("pnlPreOrder");
//rptCP.RenderControl(hw);
//pnlPreOrder.RenderControl(hw);
order.RenderControl(hw);
string output = sw.ToString();
output = "<html><head><meta charset=" + Encoding.UTF8.WebName + " /></head><body>" + output + "</body></html>";
Response.Output.Write(output);
Response.Flush();
Response.End();
lblCategorystatusReportHeader.Visible = false;
}
below is the aspx code
 
</asp:TableRow>
</asp:Table>
<table>
<tr>
<td>
 
</td>
</tr>
</table>
<table>
<%-- <tr style="text-align:center">
<td colspan="20" style="font-size:16px; padding-left:100px;background-color:#90cad9;border:1px solid black;display:none">
<b><asp:Label ID="lblCategorystatusReportHeader" runat="server" Text="Category Status Report"></asp:Label></b>
</td>
</tr>--%>
<tr>
<td style="width:150px !important;vertical-align:middle;text-align:center; border-style:solid; border-width:1px" rowspan="2">
<asp:Label ID="lblCPPre" runat="server"></asp:Label>
</td>
<td>
<%-- <asp:Panel ID="pnlPreOrder" runat="server">--%>
<table border="1" style="border-collapse:collapse">
<tr>
<%--<td stylwe="width:40px">
<asp:Label ID="lblCPPre" runat="server"></asp:Label>
</td>--%>
<td style="vertical-align:middle;background-color:#90cad9;text-align:center">
<div style="width:100px !important">Category CP</div>
</td>
<td>
<asp:Label ID="lblMessagePre" runat="server" Text="No Records found" Visible ="false" ForeColor="Red"></asp:Label>
<asp:Repeater ID="rptStylePO" runat="server" OnItemDataBound="rptStylePO_ItemDataBound">
<ItemTemplate>
<table border="1" style="border-collapse:collapse;border-spacing:0px">
<tr>
<td class="stylestatusReport">
<div style="width:100px !important"> <asp:HiddenField ID="styleid" runat="server" Value='<%# Container.DataItem.ToString() %>'/>
<asp:Label ID="lblStyle" runat="server"></asp:Label></div>
</td>
<td>
<asp:Label ID="lblNoMilestonePre" runat="server" Text="No Records found" Visible ="false" ForeColor="Red"></asp:Label>
<asp:Repeater ID="rptt" runat="server" OnItemDataBound="rptt_ItemDataBound">
<ItemTemplate>
<table>
<tr>
<td style="width:60px;vertical-align:middle;text-align:center">
<div style="width:60px !important"><asp:HiddenField ID="stlId" runat="server" Value='<%# Container.DataItem.ToString() %>' /></div>
</td>
<td>
<asp:DataList ID="dataListPO" runat="server" RepeatDirection="Horizontal" OnItemDataBound="dataListPO_ItemDataBound">
<ItemTemplate>
<table border="1" style="border-collapse:collapse; border-spacing:0px" >
<tr>
<td style="word-wrap:break-word;width:110px; height:60px; color:#000000;vertical-align:middle;text-align:center; background-color:#90cad9 ; font-size:11px;">
<div style="word-wrap:break-word;width:100%;font-size:13px">
<asp:Label ID="lblMilestoneValue" runat="server" Text='<%# Eval("MilestoneName") %>'></asp:Label></div>
</td>
</tr>
<tr>
<td style="text-align:left;">
<asp:Table ID="tblStatus" runat="server" Width="100%">
<asp:TableRow ID="rowStatus" runat="server">
<asp:TableCell ID="cellStatus1" Width="25px" runat="server"><div style="width:100px; text-align:justify"><asp:Label ID="lblForecastedDate" Font-Size="13px" runat="server" Width="50%" ForeColor="Black"></asp:Label></div></asp:TableCell>
<asp:TableCell ID="cellStatus" Width="25px" runat="server"> <div style="width:100px; text-align:center">
<asp:Label ID="lblStatus" Font-Size="13px" runat="server" ForeColor="White"></asp:Label></div>
</asp:TableCell>
</asp:TableRow></asp:Table>
<asp:HiddenField ID="hdnPlannedDate" runat="server" Value='<%# Eval("MilestonePlannedDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnRevisedDate" runat="server" Value='<%# Eval("MilestoneRevisedDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnActualDate" runat="server" Value='<%# Eval("MilestoneActualDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnMilestoneStatus" runat="server" Value='<%# Eval("MilestoneStatus") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<%-- </asp:Panel>--%>
</td>
</tr>
<tr>
<td>
<%-- <asp:Panel ID="pnlPostOrder" runat="server">--%>
<table border="1" style="border-collapse:collapse;">
<tr>
<%--<td style="width:40px">
<asp:Label ID="lblCPPost" runat="server"></asp:Label>
</td>--%>
<td style=" background-color:#90cad9; font-size:14px;vertical-align:middle;text-align:center;white-space:nowrap; " ><div style="width: 100px;">Item CP</div></td>
<td style="font-size:14px">
<asp:Label ID="lblMessagePost" runat="server" Text="No Records found" Visible ="false" ForeColor="Red"></asp:Label>
<asp:Repeater ID="rptStylePostOrder" runat="server" OnItemDataBound="rptStylePostOrder_ItemDataBound">
<ItemTemplate>
<table border="1" style="border-collapse:collapse">
<tr>
<td class="stylestatusReport">
<div style="width:100px !important"><asp:HiddenField ID="styleid" runat="server" Value='<%# Container.DataItem.ToString() %>'/>
<asp:Label ID="lblStyle" runat="server"></asp:Label></div>
</td>
<td>
<asp:Label ID="lblNoMilestonePost" runat="server" Text="No Records found" Visible ="false" ForeColor="Red"></asp:Label>
<asp:Repeater ID="rptPO" runat="server" OnItemDataBound="rptPO_ItemDataBound">
<ItemTemplate>
<table>
<tr>
<td style="word-wrap:break-word;width:60px;vertical-align:middle;text-align:center;">
<div style="width:60px">
<asp:Label ID="lblPostOrderNumber" runat="server"></asp:Label>
<asp:HiddenField ID="hdnStylePOID" runat="server" Value='<%# Container.DataItem.ToString() %>'/></div>
</td>
<td>
<asp:DataList ID="dataListPostOrder" runat="server" RepeatDirection="Horizontal" OnItemDataBound="dataListPostOrder_ItemDataBound">
<ItemTemplate>
<table border="1" style="border-collapse:collapse">
<tr>
<td style="word-wrap:break-word;width:110px; height:60px;background-color:#90cad9 ; font-size:11px;vertical-align:middle;text-align:center">
<div style="word-wrap:break-word;width:100%; font-size:13px"><asp:Label ID="lblMilestoneValuePost" runat="server" Text='<%# Eval("MilestoneName") %>'></asp:Label></div>
</td>
</tr>
<tr>
<td style="text-align:left">
<asp:Table ID="tblStatusPost" runat="server" Width="100%">
<asp:TableRow ID="rowStatusPost" runat="server">
<asp:TableCell ID="cellStatus1Post" Width="25px" runat="server">
<div style="width:100px;text-align:justify;"><asp:Label ID="lblForecastedDatePost" Font-Size="13px" runat="server" Width="50%" ForeColor="Black"></asp:Label></div></asp:TableCell>
<asp:TableCell ID="cellStatusPost" runat="server"><div style="width:100px;text-align:center">
<asp:Label ID="lblStatusPost" Font-Size="13px" runat="server" Width="100%" ForeColor="White"></asp:Label></div></asp:TableCell></asp:TableRow></asp:Table>
<asp:HiddenField ID="hdnPlannedDatePost" runat="server" Value='<%# Eval("MilestonePlannedDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnRevisedDatePost" runat="server" Value='<%# Eval("MilestoneRevisedDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnActualDatePost" runat="server" Value='<%# Eval("MilestoneActualDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnMilestoneStatusPost" runat="server" Value='<%# Eval("MilestoneStatus") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<%-- </asp:Panel>--%>
</td>
</tr>
</table>
[Below is the image of the table that is being displayed in excel.]
http://i.stack.imgur.com/JhHQo.png
actual image
[1]: http://i.stack.imgur.com/ghl8I.png
Here I had given "Showfooter"=true property but still it's not displaying
But while debug value(sumofamount) is assign to label.text
My GridView Code:
<asp:GridView ID="gvGrossDetails" runat="server" AllowPaging="true" AutoGenerateColumns="false"
CellPadding="0" CellSpacing="1" CssClass="grid_bg" GridLines="None" DataKeyNames="Code"
OnRowEditing="gvPayeeGross_RowEditing" OnRowDeleting="gvGrossDetails_RowDeleting"
OnRowUpdating="gvGrossDetails_RowUpdating" OnRowCancelingEdit="gvGrossDetails_RowCancelingEdit"
PagerStyle-Width="0px" PageSize="10" ShowFooter="true" Width="112%" Style="margin-top: 0px">
<PagerStyle CssClass="hide" />
<SelectedRowStyle CssClass="tble_hdr_not_sltd" />
<HeaderStyle CssClass="tble_hdr_not_sltd" />
<EmptyDataRowStyle CssClass="row_odd" HorizontalAlign="Center" />
<FooterStyle CssClass="hide" />
<RowStyle CssClass="row_even" />
<EmptyDataTemplate>
<table class="confirmation" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:Label Text="Records not found" ID="lblEmpty" runat="server"></asp:Label>
</td>
</tr>
</table>
</EmptyDataTemplate>
<AlternatingRowStyle CssClass="row_odd" />
<Columns>
<asp:TemplateField Visible="false">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPayeeID1" runat="server" Text='<%#Bind("Code") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="0%" />
<HeaderStyle />
</asp:TemplateField>
<asp:TemplateField Visible="false">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPayeeCode" runat="server" Text='<%#Bind("Code") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="0%" />
<HeaderStyle />
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="20%" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
Account head
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblGrossType" runat="server" Text='<%# Bind("Accounthead") %>' Wrap="true"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="item_Style1" />
<EditItemTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left" valign="middle" width="50%">
<asp:Label ID="txtGrossType" runat="server" Text='<%# Bind("Accounthead")%>'
CssClass="black_normal" Width="110px"></asp:Label>
</td>
</tr>
</table>
</EditItemTemplate>
<ItemStyle Width="20%" />
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="13%" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
Payee Amount
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPresentedAmount" runat="server" Text=' <%# Eval("PayeeAmount")%>' Wrap="true"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="item_Style1" />
<EditItemTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left" valign="middle">
<asp:Label ID="txtPresentedAmount" runat="server" Text='<%# Bind("PayeeAmount")%>'
CssClass="black_normal" onblur="requiredCheck(this);" MaxLength="5" Width="110px"></asp:Label>
</td>
</tr>
</table>
</EditItemTemplate>
<FooterTemplate>
<asp:Label Text=Text='<%# GetTotalSalary() %>' ID="lbltotal" runat="server"></asp:Label>
</FooterTemplate>
<ItemStyle Width="13%" />
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="13%" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
Approved Amount
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblApproveAmount" runat="server" Text='<%# Eval("ApprovedAmount")%>'
Wrap="true"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="item_Style1" />
<EditItemTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left" valign="middle">
<asp:TextBox ID="txtApproveAmount" runat="server" Text='<%# Bind("ApprovedAmount")%>'
CssClass="black_normal" onblur="requiredCheck(this);" MaxLength="5" Width="110px"></asp:TextBox>
<ajaxToolkit:FilteredTextBoxExtender ID="fltrApprove" runat="server" FilterType="Custom"
FilterMode="InvalidChars" InvalidChars="'abcdefghijklmnopqrstuvwxyz#!#$%^&*%<> ,"
TargetControlID="txtApproveAmount">
</ajaxToolkit:FilteredTextBoxExtender>
</td>
</tr>
</table>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="approrve" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemStyle Width="13%" />
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="6%">
<HeaderTemplate>
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="cursor: pointer;
cursor: hand;">
<tr>
<td align="right" style="display: none" valign="middle">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left" width="70%">
<a>Delete</a>
</td>
<td style="width: 6px">
</td>
</tr>
</table>
</td>
<td align="right" valign="middle">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left" width="70%">
<a>Delete</a>
</td>
<td style="width: 6px">
</td>
</tr>
</table>
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table cellpadding="0" cellspacing="0" border="0" style="padding-left: 3px">
<tr>
<td align="right" height="19px" valign="middle">
<asp:Button ID="btnSEdit" CssClass="btnEdit" runat="server" CommandName="Edit" UseSubmitBehavior="false"
CausesValidation="false" />
</td>
<td align="right" height="19px" valign="middle">
<asp:Button ID="btnSDelete" CssClass="btnDelete" runat="server" CommandName="delete"
UseSubmitBehavior="false" CausesValidation="false" />
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<td align="right" valign="middle" nowrap>
<asp:Button ID="btnSUpdate" CssClass="btnUpdate" runat="server" CommandName="Update"
UseSubmitBehavior="false" ValidationGroup="GSave" CausesValidation="false" />
<asp:Button ID="btnSCancel" CssClass="btnCancel" runat="server" CommandName="Cancel"
UseSubmitBehavior="false" CausesValidation="false" />
</td>
</tr>
</table>
</EditItemTemplate>
<ItemStyle Width="6%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
sumof total
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Separator)
{
total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "GrossAmount"));
}
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Separator)
{
total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ApprovedAmount"));
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblamount = (Label)e.Row.FindControl("lblgrossamount");
lblamount.Text = total.ToString();
}
Here i had given "Showfooter"=true property but still it's not displaying
But while debug value(sumofamount) is assign to label.text
this line apply css for the gridview infooter:
<FooterStyle CssClass="hide" />
i think that this can hide the footr of gridview pls check this css...
I have a repeater which is visible only by managers where they can accept/reject leave requests made by the users.
The following code while binding my repeater, retrieves if there are any employees on leave working in the same department and on the same date as the one requested by the user.
protected void RptLeaveRequests_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
otherEmpsLeave = new LeaveLogic().CheckEmployeeLeaveOnDateInSameDep(date, currEmp);
if (otherEmpsLeave != "")
{
//change border of repeater row to another colour and display otherEmpsLeave when manager hovers on repeater row
}
}
How can I change repeater row border colour (ex add a red border to make it stand out) and display otherEmpsLeave on hover?
ASP Repeater Code:
<h3>LEAVE REQUESTS</h3>
<asp:Label ID="LblNoRequests" Visible="false" Font-Size="14px" runat="server"></asp:Label>
<asp:HiddenField ID="dataGroups" runat="server" />
<asp:Repeater ID="RptLeaveRequests" runat="server"
onitemdatabound="RptLeaveRequests_ItemDataBound">
<ItemTemplate>
<table id="tableItem" runat="server">
<tr>
<td style="width:400px;">
<asp:Label ID="lblEmployeeId" runat="server" Text='<%#Eval("EmployeeId") %>' Visible="false" />
<asp:HiddenField ID="HdnEmployeeId" runat="server" Value='<%#Eval("EmployeeId") %>' />
<asp:Literal Text="" runat="server" ID="LiteralUser" ></asp:Literal>
</td>
</tr>
<tr>
<td style="width: 100px;">
<asp:HiddenField ID="HdnRequestId" runat="server" Value='<%#Eval("id") %>' />
<asp:Label ID="lblDate" runat="server" Text='<%#Eval("Date", "{0:dd/MM/yyyy}") %>'></asp:Label>
</td>
<td style="width: 80px;">
<asp:Label ID="lblHours" runat="server" Text='<%#Eval("Hours") %>'></asp:Label>
</td>
<td style="width: 50px; font-size:10px;">
<asp:Label ID="lblPeriod" runat="server" Text='<%#Eval("AMorPM") %>'></asp:Label>
</td>
<td style="width: 850px; font-size:10px;">
<asp:Label ID="lblNote" runat="server" Text='<%#Eval("Note") %>'></asp:Label>
</td>
<td style="width: 50px;">
<asp:RadioButtonList ID="rbtVerified" runat="server" Visible='<%#!(Boolean)Eval("ReadOnly") %>' >
<asp:ListItem Value="1">Accept</asp:ListItem>
<asp:ListItem Value="2">Reject</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:TextBox ID="txtNotes" runat="server" ></asp:TextBox>
</td>
</tr>
</table>
<div style="border-style: dotted; border-color:Black; width:100%; border-width:1px; border-color:#999999"></div>
</ItemTemplate>
</asp:Repeater>
From the MSDN example, something like
void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
// This event is raised for the header, the footer, separators, and items.
// Execute the following logic for Items and Alternating Items.
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
if (((Evaluation)e.Item.DataItem).Rating == "Good") {
((Label)e.Item.FindControl("RatingLabel")).Text= "<b>***Good***</b>";
}
}
}
instead of setting .Text set whatever property(s) you need, such as Background or Tooltip
Here is a code that I have in one of my ASPX pages:
<asp:GridView
ID="GridView1"
runat="server"
AutoGenerateColumns="False"
HorizontalAlign="Center"
ShowHeader="False"
DataSourceID="sqlTEST1">
<Columns>
<asp:BoundField DataField="stale" Visible="false" />
<asp:BoundField DataField="bad" Visible="false" />
<asp:BoundField DataField="ping" Visible="false" />
<asp:BoundField DataField="max_tags" Visible="false" />
<asp:BoundField DataField="aval_chck" Visible="false" />
<asp:TemplateField>
<ItemTemplate>
<%
if (Eval("aval_chck").ToString()=="1")
{
<table border="0" cellpadding="2" cellspacing="1">
<tr>
<td class="rowsBLACKMAINOFF" colspan="3"><asp:Label ID="Label2" runat="server" Text='<%# Bind("instalacja") %>'></asp:Label></td>
</tr>
<tr>
<td class="rowsBLACKROWOFF"><asp:Label ID="Label2" runat="server" Text='<%# Bind("stale") %>'></asp:Label></td>
<td class="rowsBLACKROWOFF"><asp:Label ID="Label3" runat="server" Text='<%# Bind("bad") %>'></asp:Label></td>
<td class="rowsBLACKROWOFF"><asp:Label ID="Label4" runat="server" Text='<%# Bind("ping") %>'></asp:Label></td>
</tr>
</table>
}
else
{
<table border="0" cellpadding="2" cellspacing="1">
<tr>
<td class="rowsBLACKMAIN" colspan="3"><asp:Label ID="Label2" runat="server" Text='<%# Bind("instalacja") %>'></asp:Label></td>
</tr>
<tr>
<td class="rowsNORMALc"> </td>
<td class="rowsNORMALc"> </td>
<td class="rowsNORMALc"> </td>
</tr>
</table>
}
%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I know it doesn't work at all.
I only wrote logically what I want to achieve
I would like to make that statement work or do something similar to that.
Any ideas?
Try GridView.RowDataBound Event
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx