update panel full post back - asp.net

i have the below code:
<asp:GridView runat="server" ID="GridView1" OnRowDataBound="gvChildGrid_RowDataBound" Width="1000px"
DataKeyNames="number" AllowSorting="false" style="font-size:15px;"
AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" AllowPaging="true" HorizontalAlign="Center"
CellPadding="4" GridLines="none">
<%-- <PagerSettings Mode="NumericFirstLast" FirstPageText="first" PreviousPageText="previous" LastPageText="last" NextPageText="next" Position="bottom" PageButtonCount="2" />--%>
<AlternatingRowStyle BackColor="#F7F7F7" />
<Columns>
<asp:TemplateField HeaderText = "Select">
<ItemTemplate>
<a href="JavaScript:divexpandcollapse('div<%# Eval("number") %>');">
<img id="imgdiv" width = "20px" src="images/Alarm-Plus-icon.png" alt="" />
</a>
</ItemTemplate>
<HeaderStyle Font-Bold="True"/>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Number">
<ItemTemplate>
<%# Eval("number")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Name">
<ItemTemplate>
<%# Eval("name")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div id="div<%# Eval("number") %>" style="display: none; position: relative; overflow: auto">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvChildGrid" DataKeyNames="number" runat="server" BackColor="Transparent" AutoGenerateColumns="false" OnPageIndexChanging="gvChildGrid_PageIndexChanging"
style="Width:100% !important;" GridLines="None" Font-Names="times new roman" AllowPaging="True" CellPadding="4" AllowSorting="True">
<HeaderStyle BackColor="#8cc63e" Font-Bold="true" ForeColor="White" />
<Columns>
<asp:BoundField DataField="number" HeaderText="Mobile Number" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="Name" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
i'm using an update pannel for the second grid view gvChildGrid because i when i use the paging of this gridview i don't want the hole page to post back... only the grid view
but the problem is that the hole page is posting back
how can i fix this?

Add Update panel to <asp:TemplateField>. It may work I'm not sure.

Related

Header Column of Gridview not aligning

The last header column of my gridview isnt aligning for some reason, im unsure why, any help?
<asp:GridView ID="gvStudents" runat="server" AutoGenerateColumns="False"
DataSourceID="SQLGetStudents" Width="100%" CssClass="table table-striped table-hover">
<alternatingrowstyle backcolor="#d0e6f4" forecolor="#545454"/>
<Columns>
<asp:BoundField DataField="PERSON_CODE" HeaderText="Student ID"
SortExpression="PERSON_CODE" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="STUDENTNAME" HeaderText="Student Name"
SortExpression="STUDENTNAME" >
<HeaderStyle Font-Bold="True" Font-Size="Larger" />
<ItemStyle Font-Bold="True" Font-Size="Larger" />
</asp:BoundField>
<asp:TemplateField HeaderStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:Label runat="server" >Add</asp:Label>
<br />
<asp:CheckBox ID="chkAll" runat="server" onclick = "checkAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkAdd" runat="server" Checked="True" onclick = "Check_Click(this)"/>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
The particular part of my gridview that doesnt seem to be working is here:
<asp:TemplateField HeaderStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:Label runat="server" >Add</asp:Label>
<br />
<asp:CheckBox ID="chkAll" runat="server" onclick = "checkAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkAdd" runat="server" Checked="True" onclick = "Check_Click(this)"/>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
but i thought id add all of the gridview just in case i messed up elsewhere
The Column shows up like this:

ASP.NET (NO JS!) hide button in DataGrid row if property empty

I have a ASP.NET DataGrid databinded from datatable after SQL query.
The DataGrid is populated with organization employee personal info.
Every row contains "Send Greeting" button.
I would like to disable or hide this button if the "Email Address" cell in that row, if Email Address is empty.
My ASP code:
<table dir="rtl">
<tr>
<asp:Label ID="lbl1" runat="server" CssClass="bDayLable" Text="Select a rpw and click on button to send greeting"></asp:Label>
</tr>
<tr>
<td colspan="2">
<div id="divMyPath" runat="server"></div>
<div id="divResults" runat="server">
<asp:DataGrid ID="grdResult" runat="server" BorderColor="#CCCCCC" BorderWidth="2px" Font-Bold="False" Font-Italic="False" Font-Names="Segoe UI" Font-Overline="False" Font-Size="13px" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Right" AutoGenerateColumns="False" Cellpadding="2" CellSpacing="2" AllowPaging="True" PageSize="4" AllowSorting="True" OnPageIndexChanged="grdResult_PageIndexChanging">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%-- <img src="\\blabla\pictures\<%# Eval("Employeeno")%>.JPG" class="phoneBookImage" />--%>
<img src="http://intranet.somedomain.com/UserProfiles/pictures/<%# Eval("Employeeno")%>.JPG" class="phoneBookImage" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Employee Name">
<ItemTemplate>
<%# Eval("firstname") & " " & Eval("surname")%>
</ItemTemplate>
</asp:TemplateColumn>
<%-- <asp:BoundColumn DataField="EmailAdd" HeaderText="Email" DataFormatString="{0:n2}"></asp:BoundColumn>--%>
<asp:TemplateColumn HeaderText="Email">
<ItemTemplate>
<a href='mailto:<%# Eval("EmailAdd")%>'> <%# Eval("EmailAdd")%> </a>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Greeting">
<ItemTemplate>
<asp:Button ButtonType="Button" ID="btnSendGreeting" runat="server" CssClass="btnSendGreeting" Text="Send Greeting" Visible="true" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<FooterStyle BackColor="#00CC00" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" />
<HeaderStyle BackColor="Gray" Font-Bold="True" Font-Italic="False" Font-Names="Segoe UI" Font-Overline="False" Font-Size="Small" Font-Strikeout="False" Font-Underline="False" ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle" />
<SelectedItemStyle BackColor="#CCFFCC" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" />
</asp:DataGrid>
</div>
</td>
</tr>
My code behind contains the function to fill the DataGrid from Data Table.
Thanks in advance!!!
Try to set the Enabled (or Visible) property like this:
<asp:Button ButtonType="Button" ID="btnSendGreeting" runat="server" CssClass="btnSendGreeting" Text="Send Greeting" Enabled='<%# Eval("EmailAdd") != null && !String.IsNullOrEmpty(Eval("EmailAdd").ToString()) %>' />
You can put all sorts of expressions between '<%# %>'.

sum asp unbound gridview column

Please I would like to get the sum or total of my total column values in the txtFootTotal text box. I can already multiply quantity and price and the value is shown in the total column so now i need to sum the total values and show the same in the textbox at the footer. Please note that my gridview textboxes are not calling back data from the database as they are unbound.
Here is my gridview
<asp:GridView ID="grvbill" runat="server"
ShowFooter="True" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333"
GridLines="None" >
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="SNo" />
<asp:TemplateField HeaderText="quantity">
<ItemTemplate>
<asp:TextBox ID="qty" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="unit price">
<ItemTemplate>
<asp:TextBox ID="price" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="all total">
<ItemTemplate>
<asp:TextBox ID="total" runat="server"
Height="55px" TextMode="MultiLine"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:TextBox ID="txtFootTotal" runat="server" Width="100px" Wrap="true" style="position:relative; right:500px;"></asp:TextBox>
<asp:Button ID="ButtonAdd" runat="server"
Text="Add New Row" OnClick="ButtonAdd_Click" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="" Font-Bold="True" ForeColor="" />
<RowStyle BackColor="" />
<EditRowStyle BackColor="" />
<SelectedRowStyle BackColor="" Font-Bold="True" ForeColor="" />
<PagerStyle BackColor="" ForeColor="" HorizontalAlign="Center" />
<HeaderStyle BackColor="" Font-Bold="true" ForeColor="" />
<AlternatingRowStyle BackColor="" />
</asp:GridView>

How to make the Header static in Gridview scroll?

here I'm trying to make a scroll-able Grid View, which I did using the overflow, but the problem is, I want to make the Header section static, allowing only the content to be scrolled, here's my code:
<div class="BodyDiv" style="overflow: auto; height: 200px">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table width="1024px">
<tr>
<td align="center">
<table width="980px">
<tr>
<td>
<asp:Panel ID="PanelDGV" runat="server" Height="250" ScrollBars="None" Width="515">
<asp:GridView ID="DGV" runat="server" AutoGenerateColumns="False" GridLines="None" AllowPaging="true" PageSize="50" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
<Columns>
<asp:BoundField DataField="ProjectCode" HeaderText="Project Code" />
<asp:BoundField DataField="ProjectName" HeaderText="Project Name" />
<asp:ButtonField ButtonType="Image" ImageUrl="../Support/Image/Edit.png" ItemStyle-HorizontalAlign="Center"
CommandName="CmdSearch" HeaderText="Edit">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
</Columns>
<PagerStyle CssClass="pgr"></PagerStyle>
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
</asp:GridView>
</asp:Panel>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
is there anyway to do it? thank you.
<script src="../Scripts/ScrollableGridPlugin.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$('#<%=Grd.ClientID %>').Scrollable();
}
)
You can download this js file from below url
http://code.google.com/p/dev-acuaman/source/browse/trunk/PyproduceEstad%C3%ACstica/EstadisticaProduce/Scripts/ScrollableGridPlugin.js?r=79
<asp:GridView ID="Grd" runat="server" Width="100%" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Country">
<ItemTemplate>
<asp:Label ID="lbl" runat="server" Text='<%# Eval("CountryName") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Enter Shipping Charge">
<ItemTemplate>
<asp:TextBox ID="txt" runat="server" Text='<%# Eval("charge") %>'></asp:TextBox>
<asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="txt"
ValidationGroup="txt" SetFocusOnError="true" Operator="DataTypeCheck" Type="Double"
ErrorMessage="Country Wise Shipping Charge must be number!">*</asp:CompareValidator>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="160px" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Enter No Of Days">
<ItemTemplate>
<asp:TextBox ID="txt1" runat="server" Text='<%# Eval("days") %>'></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txt"
ValidationGroup="txt1" SetFocusOnError="true" Operator="DataTypeCheck" Type="Integer"
ErrorMessage="No Of Days must be number!">*</asp:CompareValidator>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="160px" VerticalAlign="Middle" />
</asp:TemplateField>
</Columns>
</asp:GridView>

HtmlEncode not working in asp.net

I having a problem to make HtmlEncode work properly inside a GridView in ASP.Net. Basically I'm using TemplateField to toggle ItemTemplate and EditItemTemplate to have data entry on the GridView itself. I'm looking for some resource in how I can encode Eval and Bind method in ASP.Net but all of them not work in my end.
here's my code below:
<div id="dvShowContent" runat="server" style="text-align: center">
<asp:GridView ID="dgvSortKey" runat="server" AllowSorting="True" OnRowDataBound="gv_drb"
AutoGenerateColumns="False" AllowPaging="True" BackColor="White" BorderColor="#336666"
BorderStyle="Double" BorderWidth="3px" CellPadding="4" GridLines="Horizontal"
Height="73px" AutoGenerateEditButton="True" OnRowEditing="dgvSortKey_RowEditing"
OnRowUpdating="dgvSortKey_RowUpdating" OnRowCancelingEdit="dgvSortKey_RowCancelingEdit"
OnSelectedIndexChanging="dgvSortKey_SelectedIndexChanging" OnPageIndexChanged="dgvSortKey_PageIndexChanged"
OnPageIndexChanging="dgvSortKey_PageIndexChanging" OnRowCommand="dgvSortKey_RowCommand"
OnRowDeleted="dgvSortKey_RowDeleted" OnRowUpdated="dgvSortKey_RowUpdated" Width="561px"
PageSize="15" DataKeyNames="KeyCode,KeyDescription">
<FooterStyle BackColor="White" ForeColor="#333333" />
<RowStyle BackColor="White" ForeColor="#333333" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="LightCyan" />
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:LinkButton ID="lnkdelete" runat="server" OnClick="lnkdelete_Click">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Instruction Key Code">
<ItemTemplate>
<asp:Label ID="lblValKeyCode" runat="server" Text='<%# Server.HtmlEncode((string)Eval("KeyCode")) %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtValKeyCode" runat="server" Text='<%#Bind("KeyCode") %>' MaxLength="10"></asp:TextBox>
<%--<asp:TextBox ID="txtValKeyCode" runat="server" Text='<%#System.Web.HttpUtility.HtmlEncode(Eval("KeyCode").ToString()) %>' MaxLength="10"></asp:TextBox>--%>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" CssClass="GvBorderGreen" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblValKeyDescription" runat="server" Text='<%# Server.HtmlEncode((string)Eval("KeyDescription")) %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtValKeyDescription" runat="server" Text='<%#Bind("KeyDescription") %>'
MaxLength="10"></asp:TextBox>
<%--<asp:TextBox ID="txtValKeyDescription" runat="server" Text='<%#System.Web.HttpUtility.HtmlEncode(Eval("KeyDescription").ToString()) %>'
Width="300" MaxLength="20"></asp:TextBox>--%>
</EditItemTemplate>
<ItemStyle CssClass="GvBorderGreen" />
</asp:TemplateField>
<%--<asp:BoundField DataField="KeyCode" HeaderText="Instruction Key Code" HtmlEncode="true" />
<asp:BoundField DataField="KeyDescription" HeaderText="Description" HtmlEncode="true" />--%>
</Columns>
</asp:GridView>
</div>
Please help me to solve this problem.
As Waqar suggests the answer is in the link he provided - to make this more clear you need to change this line:
<asp:TextBox ID="txtValKeyCode" runat="server" Text='<%#Bind("KeyCode") %>' MaxLength="10"></asp:TextBox>
To this:
<asp:TextBox ID="txtValKeyCode" runat="server" Text='<%#System.Web.HttpUtility.HtmlEncode((string)Eval("KeyCode")) %>' MaxLength="10"></asp:TextBox>

Resources