How to make the Header static in Gridview scroll? - asp.net

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>

Related

Page containing multiple Gridview RowEditing Event not firing

Web page is designed using .Net framework 4.5. Web pages contains 3 Grid views as follows:
Code for Gridview is as follows:
<asp:GridView ID="grdADetails" runat="server" AutoGenerateColumns="False" CssClass="tGrid" GridLines="Horizontal" ShowFooter="True" Width="100%" OnRowCancelingEdit="grdADetails_RowCancelingEdit" OnRowCommand="grdADetails_RowCommand" OnRowDataBound="grdADetails_RowDataBound" OnRowDeleting="grdADetails_RowDeleting" OnRowEditing="grdADetails_RowEditing" OnRowUpdating="grdADetails_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="Mode Of Transport">
<EditItemTemplate>
<asp:DropDownList ID="DrpTMode" runat="server" CssClass="trvGridCmbBox" Width="90%">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="WIDTH: 100%">
<tr>
<td class="tGridTotal" style="Height : 25px;"></td>
</tr>
<tr>
<td class="GridEditArea" style="Height : 25px;">
<asp:DropDownList ID="DrpNTMode" runat="server" CssClass="trvGridCmbBox" Font-Size="8pt" Width="98%">
</asp:DropDownList>
</td>
</tr>
</table>
</FooterTemplate>
<HeaderTemplate>
<asp:Label ID="lblTMode" runat="server" Text="<%$ Resources:EResources, lblModeOfT %>" Width="100%"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblESubTypeCode" runat="server" Text='<%# Bind("ESubTypeCode") %>' Visible="False"></asp:Label>
<asp:Label ID="lblTMode" runat="server" Text='<%# Bind("TMode") %>'></asp:Label>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="12%" />
</asp:TemplateField>
//For Date part using Ajax Control
<asp:TemplateField HeaderText="Departure On">
<EditItemTemplate>
<asp:TextBox ID="txtDeptOn" runat="server" CssClass="trvGridTextBox" Text='<%# Bind("DeptOn") %>' Width="90%"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="ceDeptOn" runat="server" Format="MM/dd/yyyy" TargetControlID="txtDeptOn" Enabled="true" Animated="true" EnabledOnClient="true" EnableViewState="true" FirstDayOfWeek="Default"/>
</EditItemTemplate>
<FooterTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="WIDTH: 100%">
<tr>
<td class="tGridTotal" style="Height : 25px;"></td>
</tr>
<tr>
<td class="GridEditArea" style="Height : 25px;">
<asp:TextBox ID="txtNewDeptOn" runat="server" CssClass="trvGridTextBox" Width="100%"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="ceNewDeptOn" runat="server" Enabled="true" Format="MM/dd/yyyy" TargetControlID="txtNewDeptOn" Animated="true" EnabledOnClient="true" EnableViewState="true" FirstDayOfWeek="Default"/>
</td>
</tr>
</table>
</FooterTemplate>
<HeaderTemplate>
<asp:Label ID="lblDepartureOn" runat="server" Text="<%$ Resources:EASEResources, lblDeparOn %>" Width="100%"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblDeptOn" runat="server" Text='<%# Bind("DeptOn") %>'></asp:Label>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="10%" />
</asp:TemplateField>
//Same as above for remaining columns
//For Edit button column
<asp:TemplateField HeaderText="Edit">
<EditItemTemplate>
<asp:ImageButton ID="ImgUpdate" runat="server" CommandName="Update" ImageUrl="~/PL/images/save.png" />
<asp:ImageButton ID="ImageButton4" runat="server" CommandName="Cancel" ImageUrl="~/PL/images/remove1.png" />
</EditItemTemplate>
<FooterTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="WIDTH: 100%">
<tr>
<td class="tGridTotal" style="height: 25px"></td>
</tr>
<tr>
<td class="GridEditArea" aria-orientation="vertical" style="height: 25px">
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="AddNew" CssClass="trvGridTextBox" ImageUrl="~/PL/images/save.png" />
</td>
</tr>
</table>
</FooterTemplate>
<HeaderTemplate>
<asp:Label ID="lblEdit" runat="server" Text="<%$ Resources:EResources, lblEdit %>" Width="100%"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" CommandName="Edit" ImageUrl="~/PL/images/edit.png" />
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="4%" />
</asp:TemplateField>
Remaining two grid views are created in the similar format.
<asp:GridView ID="GrdTDetail" runat="server" AutoGenerateColumns="False" CssClass="travelGrid" GridLines="Horizontal" ShowFooter="True" Width="100%" OnRowCancelingEdit="GrdTDetail_RowCancelingEdit" OnRowCommand="GrdTDetail_RowCommand" OnRowDataBound="GrdTDetail_RowDataBound" OnRowDeleting="GrdTDetail_RowDeleting" OnRowEditing="GrdTDetail_RowEditing" OnRowUpdating="GrdTDetail_RowUpdating">
<Columns>
//Other Column Code
//Edit Column Code.
<asp:TemplateField HeaderText="Edit">
<EditItemTemplate>
<asp:ImageButton ID="ImageButton3" runat="server" CausesValidation="False" CommandName="Update" ImageUrl="~/PL/images/save.png" />
<asp:ImageButton ID="ImageButton4" runat="server" CausesValidation="False" CommandName="Cancel" ImageUrl="~/PL/images/remove1.png" />
</EditItemTemplate>
<FooterTemplate>
<table border="0" style="WIDTH: 100%">
<tr>
<td class="travelGridTotal" style="Height : 25px;"></td>
</tr>
<tr>
<td class="GridEditArea" style="Height : 25px;">
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="AddNewACC" CssClass="trvGridTextBox" ImageUrl="~/PL/images/save.png" />
</td>
</tr>
</table>
</FooterTemplate>
<HeaderTemplate>
<asp:Label ID="lblEdit" runat="server" Text="<%$ Resources:EResources, lblEdit %>" Width="100%"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" CommandName="Edit" ImageUrl="~/PL/images/edit.png" />
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="4%" />
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="GridFooter" />
<HeaderStyle CssClass="travelGridhead" /
</asp:GridView>
//3rd Gridview code
<asp:GridView ID="GrdOtherExp" runat="server" AutoGenerateColumns="False" CellPadding="0" CssClass="travelGrid" GridLines="Horizontal" ShowFooter="True" Width="100%" OnRowCancelingEdit="GrdOtherExp_RowCancelingEdit" OnRowCommand="GrdOtherExp_RowCommand" OnRowDataBound="GrdOtherExp_RowDataBound" OnRowDeleting="GrdOtherExp_RowDeleting" OnRowEditing="GrdOtherExp_RowEditing" OnRowUpdating="GrdOtherExp_RowUpdating">
<Columns>
//Other Column Code
//Edit Column Code
<asp:TemplateField HeaderText="Edit">
<EditItemTemplate>
<asp:ImageButton ID="ImageButton3" runat="server" CausesValidation="False" CommandName="Update" ImageUrl="~/PL/images/save.png" />
<asp:ImageButton ID="ImageButton4" runat="server" CausesValidation="False" CommandName="Cancel" ImageUrl="~/PL/images/close.png" />
</EditItemTemplate>
<FooterTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="WIDTH: 100%">
<tr>
<td class="travelGridTotal"></td>
</tr>
<tr>
<td class="GridEditArea"> <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="AddNewOExp" CssClass="trvGridTextBox" ImageUrl="~/PL/images/save.png" Height="16px" Width="16px" />
</td>
</tr>
</table>
</FooterTemplate>
<HeaderTemplate>
<asp:Label ID="lblEdit" runat="server" Text="<%$ Resources:EResources, lblEdit %>" Width="100%"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" CommandName="Edit" ImageUrl="~/PL/images/edit.png" />
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="2%" />
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="GridFooter" />
<HeaderStyle CssClass="travelGridhead" /
</asp:GridView>
Each grid view has its own RowEditing, RowDataBound, RowUpdating, RowCancelEditing events. Gridview functionality is as follows:
User can enter data from footer row and using Save button having
command name as 'AddNew' saves the entered data to Item template in
row format. RowCommand event code is as follows:
protected void grdADetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
DataTable dtADetails = (DataTable)ViewState["dtAccDetails"];
ViewState["dtADetails"] = dtADetails;
if (e.CommandName.Equals("AddNew"))
{
//function to add data
//function to check required fields
}
}
User can edit and update the row data on RowEding event. Row edit button has command name as 'Edit'.
protected void grdADetails_RowEditing(object sender, GridViewEditEventArgs e)
{
grdADetails.EditIndex = e.NewEditIndex;
DataTable dtADetails = (DataTable)ViewState["dtADetails"];// cache data to session
//Code for editing the functionality.
}
User can save the edited row data or cancel the editing.
After publishing the pages to production server only one grid view events get fired, remaining two grid view events do not gets fired. Each editing button has command name as 'Edit' to fire edit event. Each

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 '<%# %>'.

update panel full post back

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.

FormView Layout

This has driven me crazy a few times in the past but I've always fudged it and moved on. Today I want to try and fix it!
I quite frequently create a GridView to display data and a FormView directly beneath in Insert mode with controls in the InsertItemTemplate corresponding to the columns in the GridView, so that it looks like the FormView is just an empty row of the GridView awaiting new data entry. This works great.
The problem is that I can never get the widths of the 'columns' (really just textboxes) in the FormView to correspond to the widths of the columns in the GridView above.
In the example below, as you can see, both the GridView and FormView have a width of 100% and, sure enough, when the page is rendered they're both exactly the same width (I gave the FormView a border briefly to check). However, even though the widths of the textboxes in the FormView are identical to the widths of the columns in the GridView, they don't display that way. The textboxes are slightly wider, and by the time you get to the right-most column the cumulative effect means that the alignment is way out.
I'm guessing the problem is something to do with border widths or some other hidden element which is being rendered, but I can't figure it out. I have to say, the amount by which the alignment is out seems more than the couple of pixels a border would affect things.
<asp:GridView ID="gvTPR" runat="server" DataSourceID="SQLTPR" AutoGenerateColumns="false" DataMember="DefaultView" DataKeyNames="TPRID" Width="100%" >
<RowStyle HorizontalAlign="Center" />
<EditRowStyle BackColor="#ccffff" />
<HeaderStyle BackColor="#013b82" ForeColor="White" />
<Columns>
<asp:BoundField DataField="TPREnteredAt" HeaderText="Entered At" ReadOnly="True" SortExpression="TPREnteredAt" ItemStyle-Width="24%" ControlStyle-Width="90%" />
<asp:BoundField DataField="TPRTemp" HeaderText="Temp" ReadOnly="True" SortExpression="TPRTemp" ItemStyle-Width="12%" ControlStyle-Width="90%"/>
<asp:BoundField DataField="TPRPulse" HeaderText="Pulse" ReadOnly="True" SortExpression="TPRPulse" ItemStyle-Width="12%" ControlStyle-Width="90%"/>
<asp:BoundField DataField="TPRRespiration" HeaderText="Respiration" ReadOnly="True" SortExpression="TPRRespiration" ItemStyle-Width="12%" ControlStyle-Width="90%"/>
<asp:BoundField DataField="TPRPCV" HeaderText="PCV" ItemStyle-Width="12%" ControlStyle-Width="90%"/>
<asp:BoundField DataField="TPRTP" HeaderText="TP" ItemStyle-Width="12%" ControlStyle-Width="90%" />
<asp:CommandField ButtonType="Button" InsertVisible="False" ShowEditButton="True" ItemStyle-Width="16%" UpdateText="Save" ControlStyle-Width="60px" />
</Columns>
<EmptyDataTemplate>
No TPR records exist
</EmptyDataTemplate>
</asp:GridView>
<asp:FormView ID="fvTPR" runat="server" DataSourceID="SQLTPR" DefaultMode="Insert" Width="100%" >
<InsertItemTemplate>
<asp:textbox ID="lblEnteredAt" runat="server" Text="Will be added automatically" Width="24%" />
<asp:TextBox ID="txtTemp" runat="server" Text='<%# Bind("TPRTemp")%>' Width="12%" />
<asp:TextBox ID="txtPulse" runat="server" Text='<%# Bind("TPRPulse")%>' Width="12%" />
<asp:TextBox ID="txtRespiration" runat="server" Text='<%# Bind("TPRRespiration")%>' Width="12%" />
<asp:TextBox ID="txtPCV" runat="server" Text='<%# Bind("TPRPCV")%>' Width="12%" />
<asp:TextBox ID="txtTP" runat="server" Text='<%# Bind("TPRTP")%>' Width="12%" />
<asp:Button ID="btnAddTPR" runat="server" Text="Save" Width="5%" />
</InsertItemTemplate>
</asp:FormView>
This renders like this:
How about using GridView footer for add funcionality? This way you will have all columns in same table and you'l get around your positioning problems.
Here is an example of how your gridview should look like:
<asp:GridView ID="gvTPR" runat="server" DataSourceID="SQLTPR" AutoGenerateColumns="False" ShowFooter="True" DataKeyNames="TPRID" Width="100%" EnableModelValidation="True">
<RowStyle HorizontalAlign="Center" />
<EditRowStyle BackColor="#ccffff" />
<HeaderStyle BackColor="#013b82" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="Entered At" SortExpression="TPREnteredAt">
<EditItemTemplate>
<asp:TextBox ID="lblEnteredAt" runat="server" Text='<%# Eval("TPREnteredAt") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("TPREnteredAt") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="90%" />
<ItemStyle Width="24%" />
<FooterTemplate>
<asp:TextBox ID="lblEnteredAt" runat="server" Text="Will be added automatically" Width="24%" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Temp" SortExpression="TPRTemp">
<EditItemTemplate>
<asp:TextBox ID="txtTemp" runat="server" Text='<%# Eval("TPRTemp") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("TPRTemp") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTemp" runat="server" Text='<%# Bind("TPRTemp")%>' Width="12%" />
</FooterTemplate>
<ControlStyle Width="90%" />
<ItemStyle Width="12%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Pulse" SortExpression="TPRPulse">
<EditItemTemplate>
<asp:TextBox ID="txtPulse" runat="server" Text='<%# Eval("TPRPulse") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("TPRPulse") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPulse" runat="server" Text='<%# Bind("TPRPulse")%>' Width="12%" />
</FooterTemplate>
<ControlStyle Width="90%" />
<ItemStyle Width="12%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Respiration" SortExpression="TPRRespiration">
<EditItemTemplate>
<asp:TextBox ID="txtRespiration" runat="server" Text='<%# Eval("TPRRespiration") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("TPRRespiration") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtRespiration" runat="server" Text='<%# Bind("TPRRespiration")%>' Width="12%" />
</FooterTemplate>
<ControlStyle Width="90%" />
<ItemStyle Width="12%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="PCV">
<EditItemTemplate>
<asp:TextBox ID="txtPCV" runat="server" Text='<%# Bind("TPRPCV") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("TPRPCV") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPCV" runat="server" Text='<%# Bind("TPRPCV")%>' Width="12%" />
</FooterTemplate>
<ControlStyle Width="90%" />
<ItemStyle Width="12%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="TP">
<EditItemTemplate>
<asp:TextBox ID="txtTP" runat="server" Text='<%# Bind("TPRTP") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("TPRTP") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTP" runat="server" Text='<%# Bind("TPRTP")%>' Width="12%" />
</FooterTemplate>
<ControlStyle Width="90%" />
<ItemStyle Width="12%" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="lnkbtnEdit" runat="Server" Text="Edit" CommandName="Edit"
CausesValidation="false"></asp:Button>
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="lnkbtnUpdate" runat="Server" Text="Save" CommandName="Update"
CausesValidation="true"></asp:Button><br />
<asp:LinkButton ID="lnkbtnCancel" runat="Server" Text="Cancel" CommandName="Cancel"
CausesValidation="false"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lnkbtnInsert" runat="Server" Text="Save" CommandName="Insert"
CausesValidation="true"></asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No TPR records exist
</EmptyDataTemplate>
</asp:GridView>
Hope this helps!
Regards,
Uros

ASP.NET Web application performs slow in client PC

I am developing a ASP.NET web application. One of my from perform very slow in client machine. Where I use GridView which include some function and some control on there like combo-box input box, each control have some function and calculation on there leave.
Please suggest me how can I improve this?
Page on content.
- GridView
1. Combobox with jquery datafiltering
2. Inputbox with data check function
3. More function of grid like update,add, new, delete.
I am also use Viewsate on this page.
<%# Page Title="" Language="C#" MasterPageFile="~/UI/Healthcare.Master" AutoEventWireup="true" CodeBehind="frmStockIn.aspx.cs" Inherits="Com.Codespecies.Healthcare.UI.Pharmacy.frmStockIn" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder_header" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
...........
....
....
<div class="box_bg" style="height: auto; width: 1020px; border: 0px solid; border-color: #0167AA; margin:5px 0px 0px 0px; float:left;">
<div style=" min-height:30px; width: 1005px; padding: 0px 0px 0px 2px;">
<div style="min-height: 30px; width:auto; width:300px; float: left; font-weight: bold;">
Drugs Details
</div>
<div style="min-height: 30px; width: 600px; float: left;">
<div id="msg" style="height:auto; float:left;">
<asp:Label ID="lblMsg" runat="server" Text=" "></asp:Label>
</div>
<div id="ajaxLoader" style=" display:none; margin:2px 0px 0px 0px; float:left;">
<img height="20px" width="20px" src="../../image/ajax-loading/ajax-loading-2.gif" alt="loader" border="0" style=""/>
</div>
</div>
</div>
<div style=" width: auto; padding: 0px 0px 5px 0px;">
<asp:GridView ID="gvStockIn" runat="server" AllowPaging="True" Width="1020px"
AlternatingRowStyle-HorizontalAlign="Left" AlternatingRowStyle-VerticalAlign="Middle"
AutoGenerateColumns="False" BorderStyle="None" DataKeyNames="ID"
Font-Names="Calibri" Font-Size="Small" ForeColor="#333333" GridLines="None"
PageSize="100" ShowFooter="True" ShowHeaderWhenEmpty="True"
onrowcancelingedit="gvStockIn_RowCancelingEdit" onrowcommand="gvStockIn_RowCommand"
onrowdeleting="gvStockIn_RowDeleting" onrowediting="gvStockIn_RowEditing"
onrowupdating="gvStockIn_RowUpdating" onrowdatabound="gvStockIn_RowDataBound"
AllowSorting="True" TabIndex="5">
<AlternatingRowStyle BackColor="#DCEEFC" Font-Names="Calibri" HorizontalAlign="Left" VerticalAlign="Middle" />
<Columns>
<asp:TemplateField HeaderText="SL" SortExpression="ID">
<ItemStyle Width="30px" />
<HeaderStyle Width="30px" />
<FooterStyle Width="30px" />
<EditItemTemplate>
<asp:Label ID="lblSerialNo" runat="server" Text='<%# Eval("ID") %>' Width="30px"></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblNewSerialNo" runat="server" Width="30px">NA</asp:Label>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblSerialNo" runat="server" Text='<%# Bind("ID") %>' Width="30px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Drug" >
<ItemStyle Width="170px" />
<HeaderStyle Width="170px" />
<FooterStyle Width="170px" />
<EditItemTemplate>
<asp:Label ID="lblDrug" runat="server" Text='<%# Bind("DRUG_NAME") %>' Width="170px"></asp:Label>
<%--<asp:TextBox ID="txtDrug" runat="server" CssClass="Drug" Text='<%# Eval("DRUG_NAME") %>' Width="100px"></asp:TextBox>--%>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList CssClass="fire_selected_change_event combobox combobox1" ID="ddlNewDrug" runat="server" onselectedindexchanged="ddlNewDrug_SelectedIndexChanged">
</asp:DropDownList>
<%--<asp:TextBox ID="txtNewDrug" runat="server" CssClass="Drug" Width="100px"></asp:TextBox>--%>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblDrug" runat="server" Text='<%# Bind("DRUG_NAME") %>' Width="170px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Presentation">
<ItemStyle Width="130px" />
<HeaderStyle Width="130px" />
<FooterStyle Width="130px" CssClass="drug_list1"/>
<EditItemTemplate>
<asp:Label ID="lblPresentation" runat="server" Text='<%# Bind("PRESENTATION_NAME") %>' Width="130px"></asp:Label>
<%--<asp:TextBox ID="txtPresentation" runat="server" CssClass="Presentation" Text='<%# Eval("PRESENTATION_NAME") %>' Width="110px"></asp:TextBox>--%>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList CssClass="fire_selected_change_event combobox combobox1" ID="ddlNewPresentation" runat="server" AutoPostBack="True" onselectedindexchanged="ddlNewPresentation_SelectedIndexChanged">
</asp:DropDownList>
<%--<asp:TextBox ID="txtNewPresentation" runat="server" CssClass="Presentation" Width="110px"></asp:TextBox>--%>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblPresentation" runat="server" Text='<%# Bind("PRESENTATION_NAME") %>' Width="130px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Strength">
<ItemStyle Width="130px" />
<HeaderStyle Width="130px" />
<FooterStyle Width="130px" CssClass="drug_list1"/>
<EditItemTemplate>
<asp:Label ID="lblUnitStrength" runat="server" Text='<%# Bind("DRUG_UNIT_STRENGTH") %>' Width="110px"></asp:Label>
<%--<asp:TextBox ID="txtUnitStrength" runat="server" CssClass="UnitStrength" Text='<%# Eval("DRUG_UNIT_STRENGTH") %>' Width="110px"></asp:TextBox>--%>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList CssClass="fire_selected_change_event combobox combobox1" ID="ddlNewUnitStrength" runat="server" AutoPostBack="True" onselectedindexchanged="ddlNewUnitStrength_SelectedIndexChanged">
</asp:DropDownList>
<%--<asp:TextBox ID="txtNewUnitStrength" runat="server" CssClass="UnitStrength" Width="110px"></asp:TextBox>--%>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblUnitStrength" runat="server" Text='<%# Bind("DRUG_UNIT_STRENGTH") %>' Width="110px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mfg Date">
<ItemStyle Width="65px" />
<HeaderStyle Width="65px" />
<FooterStyle Width="65px" />
<EditItemTemplate>
<asp:TextBox ID="txtManufacturerDate" runat="server" CssClass="date_property" Text='<%# Eval("DRUG_MANUFACTURER_DATE", "{0:dd/MM/yyyy}") %>' Height="25px" Width="65px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewManufacturerDate" runat="server" CssClass="date_property" Height="25px" Width="65px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblManufacturerDate" runat="server" Text='<%# Bind("DRUG_MANUFACTURER_DATE", "{0:dd/MM/yyyy}") %>' Height="25px" Width="65px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Exp. Date">
<ItemStyle Width="65px" />
<HeaderStyle Width="65px" />
<FooterStyle Width="65px" />
<EditItemTemplate>
<asp:TextBox ID="txtExpireDate" runat="server" CssClass="date_property" Text='<%# Eval("DRUG_EXPIRE_DATE", "{0:dd/MM/yyyy}") %>' Height="25px" Width="65px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewExpireDate" runat="server" CssClass="date_property" Height="25px" Width="65px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblExpireDate" runat="server" Text='<%# Bind("DRUG_EXPIRE_DATE", "{0:dd/MM/yyyy}") %>' Height="25px" Width="65px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty">
<ItemStyle Width="40px" HorizontalAlign="Right" />
<HeaderStyle Width="40px" HorizontalAlign="Right" />
<FooterStyle Width="40px" HorizontalAlign="Right" />
<EditItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server" CssClass="check_decimal Quantity" Text='<%# Eval("QUANTITY") %>' Height="25px" Width="40px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewQuantity" runat="server" CssClass="check_decimal Quantity" Height="25px" Width="40px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblQuantity" runat="server" Text='<%# Bind("QUANTITY") %>' Height="25px" Width="40px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cost Price">
<ItemStyle Width="70px" HorizontalAlign="Right"/>
<HeaderStyle Width="70px" HorizontalAlign="Right"/>
<FooterStyle Width="70px" HorizontalAlign="Right"/>
<EditItemTemplate>
<asp:TextBox ID="txtCostPrice" runat="server" CssClass="check_decimal CostPrice" Text='<%# Eval("COST_PRICE") %>' ontextchanged="txtCostPrice_TextChanged" AutoPostBack="true" Height="25px" Width="60px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewCostPrice" runat="server" CssClass="check_decimal CostPrice" ontextchanged="txtNewCostPrice_TextChanged" AutoPostBack="true" Height="25px" Width="60px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblCostPrice" runat="server" Text='<%# Bind("COST_PRICE") %>' Height="25px" Width="60px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sale Price">
<ItemStyle Width="70px" HorizontalAlign="Right"/>
<HeaderStyle Width="70px" HorizontalAlign="Right"/>
<FooterStyle Width="70px" HorizontalAlign="Right"/>
<EditItemTemplate>
<asp:TextBox ID="txtSellPrice" runat="server" CssClass="check_decimal SellPrice" Text='<%# Eval("SELL_PRICE") %>' Height="25px" Width="60px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewSellPrice" runat="server" CssClass="check_decimal SellPrice" Height="25px" Width="60px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblSellPrice" runat="server" Text='<%# Bind("SELL_PRICE") %>' Height="25px" Width="60px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Discount">
<ItemStyle Width="60px" HorizontalAlign="Right"/>
<HeaderStyle Width="60px" HorizontalAlign="Right"/>
<FooterStyle Width="60px" HorizontalAlign="Right"/>
<EditItemTemplate>
<asp:TextBox ID="txtDiscount" runat="server" CssClass="check_decimal percentage" Text='<%# Eval("DISCOUNT") %>' Height="25px" Width="60px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewDiscount" runat="server" CssClass="check_decimal percentage" Height="25px" Width="60px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblDiscount" runat="server" Text='<%# Bind("DISCOUNT") %>' Height="25px" Width="60px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sub Total">
<ItemStyle Width="70px" HorizontalAlign="Right"/>
<HeaderStyle Width="70px" HorizontalAlign="Right"/>
<FooterStyle Width="70px" HorizontalAlign="Right"/>
<EditItemTemplate>
<asp:TextBox ID="txtSubTotal" runat="server" CssClass="check_decimal" Text='<%# Eval("SUB_TOTAL_AMOUNT") %>' ontextchanged="txtSubTotal_TextChanged" AutoPostBack="true" Height="25px" Width="70px"></asp:TextBox>
<%--<asp:Label ID="lblSubTotal" runat="server" Text='<%# Eval("SUB_TOTAL_AMOUNT") %>' Height="25px" Width="80px"></asp:Label>--%>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewSubTotal" runat="server" CssClass="check_decimal" Text='' ontextchanged="txtNewSubTotal_TextChanged" AutoPostBack="true" Height="25px" Width="70px"></asp:TextBox>
<%--<asp:Label ID="lblSubTotal" runat="server" Text='' Height="25px" Width="80px"></asp:Label>--%>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblSubTotal" runat="server" Text='<%# Bind("SUB_TOTAL_AMOUNT") %>' Height="25px" Width="70px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ShowHeader="False">
<ItemStyle Width="100px" HorizontalAlign="Center"/>
<HeaderStyle Width="100px" HorizontalAlign="Center"/>
<FooterStyle Width="100px" HorizontalAlign="Center"/>
<EditItemTemplate>
<asp:ImageButton ID="lnkUpdate" ToolTip="Update" runat="server" OnClientClick="load_ajax_drugs_details();" ImageUrl="../../image/update.png" Height="25px" Width="25px" CausesValidation="False" CommandArgument="" CommandName="Update" ></asp:ImageButton>
<asp:ImageButton ID="lnkCancel" ToolTip="Cancel" runat="server" OnClientClick="load_ajax_drugs_details();" ImageUrl="../../image/cancel.png" Height="25px" Width="25px" CausesValidation="False" CommandArgument="" CommandName="Cancel" ></asp:ImageButton>
<%-- <asp:LinkButton ID="lnkUpdate" runat="server" CausesValidation="False" OnClientClick="load_ajax_drugs_details();" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False" OnClientClick="load_ajax_drugs_details();" CommandName="Cancel" Text="Cancel"></asp:LinkButton>--%>
</EditItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="lnkNew" ToolTip="New" runat="server" OnClientClick="load_ajax_drugs_details();" ImageUrl="../../image/add.png" Height="25px" Width="25px" CausesValidation="False" CommandArgument="" CommandName="New" ></asp:ImageButton>
<asp:ImageButton ID="lnkRefresh" ToolTip="Refresh" runat="server" OnClientClick="load_ajax_drugs_details();" ImageUrl="../../image/refresh.png" Height="25px" Width="25px" CausesValidation="False" CommandArgument="" CommandName="Refresh" ></asp:ImageButton>
</FooterTemplate>
<ItemTemplate>
<asp:ImageButton ID="lnkEdit" ToolTip="Edit" runat="server" OnClientClick="load_ajax_drugs_details();" ImageUrl="../../image/edit.png" Height="25px" Width="25px" CausesValidation="False" CommandArgument="" CommandName="Edit" ></asp:ImageButton>
<%--<asp:LinkButton ID="lnkEdit" ToolTip="Edit" runat="server" OnClientClick="load_ajax_drugs_details();" ImageUrl="../../image/edit.png" Height="10px" Width="15px" CausesValidation="False" CommandArgument="" CommandName="Edit" Text="Edit"></asp:LinkButton>--%>
<asp:ImageButton ID="lnkDelete" ToolTip="Delete" runat="server" OnClientClick="load_ajax_drugs_details();" ImageUrl="../../image/delete.png" Height="25px" Width="25px" CausesValidation="False" CommandArgument="" CommandName="Delete" ></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#507CD1" ForeColor="White" HorizontalAlign="Left" VerticalAlign="Middle" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Right" VerticalAlign="Middle" />
<RowStyle Font-Names="Calibri" />
<FooterStyle CssClass="drug_list"></FooterStyle>
</asp:GridView>
</div>
.....
.....
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Content>
}
There is a lot of reasons for this issue.As far as i under stood from your question I will suggest some places where you need to take a look at.
1)Check how much data you retrieves from database in order to show the gridview primarily.
2)adding the above controls to the gridview won't make it perform badly.But the calculations you where talking about may be a cause.Take a deep look at the code ,check whether there is any long running loops or some thing else is there.
3)if the first two is not helping you make a profiling.For your problem you just need a trial version of ants performance profiler.
After installing the profile find out which database call or .net function is taking more time to execute then debug it.

Resources