I have the following UI design for a nested GridView. According to that I want a solution for exporting a nested Gridview into Excel.
Nested GridView
<asp:GridView ID="Mastergrid" PageSize="20" AllowPaging="true" Width="100%" Height="100%" OnPageIndexChanging="Mastergrid_PageIndexChanging" runat="server" AutoGenerateColumns="false" CssClass="gridview" DataKeyNames="r_id" OnRowDataBound="Mastergrid_RowDataBound" ShowHeaderWhenEmpty="true">
<Columns>
<asp:TemplateField HeaderText="id" Visible="false">
<ItemTemplate>
<asp:Label ID="lblr_id" runat="server" Text='<%# Eval("r_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reg. No">
<ItemTemplate>
<asp:Label ID="lblregid" runat="server" Text='<%# Eval("r_uid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblname" runat="server" Text='<%# Eval("name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Indos No.">
<ItemTemplate>
<asp:Label ID="lblindosno" runat="server" Text='<%# Eval("indos_no") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Course Infomation">
<ItemTemplate>
<asp:GridView ID="subgrid" ShowHeader="true" runat="server" AutoGenerateColumns="false" Width="100%" Height="100%" EmptyDataText="No Record found..!!" CssClass="gridview1">
<Columns>
<asp:TemplateField HeaderText="Course id" Visible="false" HeaderStyle-Width="5%" >
<ItemTemplate>
<asp:Label ID="Course_id" runat="server" Text='<%# Eval("Course_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Course Name" HeaderStyle-Width="60%">
<ItemTemplate>
<asp:Label ID="lblcoursename" runat="server" Text='<%# Eval("course_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Course Fees" >
<ItemTemplate>
<asp:Label ID="lblcoursefees" runat="server" Text='<%# Eval("course_fees") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Course Date">
<ItemTemplate>
<asp:Label ID="lblcoursedate" runat="server" Text='<%# Eval("course_date","{0:dd-MM-yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You need to find the nested grid with FindControl:
protected void Mastergrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "exportNestedGrid")
{
//convert the CommandArgument
int rowNumber = Convert.ToInt32(e.CommandArgument);
//find the nested GridView
GridView gridview = GridView1.Rows[rowNumber].FindControl("subgrid") as GridView;
//do stuff with the nested GridView
gridview.Visible = false;
}
}
And for getting the rowNumber, you could send it along with the export button:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" CommandArgument='<%# Container.DataItemIndex %>' CommandName="exportNestedGrid" runat="server" Text="Export nested GridView" />
</ItemTemplate>
</asp:TemplateField>
we can export Nested Gridview same as simple gridview into the excel.
Related
how can i change the width of the gridview items? i tried adding itemstyle-width but it doesnt change anything. is it because my gridview is too crowded and does not fit into my screen or something is wrong with my codes?
<asp:GridView ID="gvModal" runat="server" AutoGenerateColumns="false" DataKeyNames="ID" EmptyDataText="No Records" AllowPaging="true" CellPadding="4" HeaderStyle-BackColor="CornflowerBlue" BorderWidth="2" BorderColor="CornflowerBlue" Width="100%" CssClass="table table-hover" >
<Columns>
<asp:TemplateField HeaderText ="ID" HeaderStyle-ForeColor="White">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%#Bind ("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Type" HeaderStyle-Width="230px" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri" >
<ItemTemplate>
<asp:Label ID="lbltype" runat="server" Text='<%#Bind ("ItemType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Model" HeaderStyle-Width="240px" ItemStyle-Width="300px" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblModel" runat="server" Text='<%# Bind("ItemModel") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Requested Quantity" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblQuan" runat="server" Text='<%#Bind ("ItemQuantity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="AMS Balance" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblAMS" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Incoming Stock" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblIncoming" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Unit" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblUnit" runat="server" Text='<%#Bind ("ItemUnit") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Date Needed" HeaderStyle-Width="180px" ItemStyle-Width="150px" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblDate" runat="server" Text='<%#Bind ("ItemDate" , "{0:yyyy-MM-dd}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Description" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%#Bind ("ItemDesc") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Status" ItemStyle-Width="120px" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%#Bind ("ItemStatus") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="PO Number" HeaderStyle-ForeColor="White" ItemStyle-Width="120px" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblPONumber2" runat="server" Text='<%#Bind ("PO_Num") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="PO Date" HeaderStyle-ForeColor="White" ItemStyle-Width="150px" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblPODate2" runat="server" Text='<%#Bind ("PO_Date", "{0:yyyy-MM-dd}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Delivery Date" HeaderStyle-ForeColor="White" ItemStyle-Width="150px" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblDelDate2" runat="server" Text='<%#Bind ("Delivery_Date", "{0:yyyy-MM-dd}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Issuance Date" HeaderStyle-ForeColor="White" ItemStyle-Width="180px" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblIssDate2" runat="server" Text='<%#Bind ("IssuanceDate", "{0:yyyy-MM-dd}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Issuance Number" HeaderStyle-ForeColor="White" ItemStyle-Width="110px" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblIssNum2" runat="server" Text='<%#Bind ("IssuanceNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Issuance" ItemStyle-Font-Names="Calibri" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="#336699" ItemStyle-Width="170px">
<ItemTemplate>
<asp:Label ID ="lblIssued" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="#336699" ItemStyle-Font-Names="Calibri" ItemStyle-Width="80px">
<ItemTemplate>
<asp:Label ID ="lblQuantity" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="#336699" ItemStyle-Font-Names="Calibri" ItemStyle-Width="80px">
<ItemTemplate>
<asp:Label ID ="lblUnits" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The width is specified as 100% in the gridview bit in the columns , you are using px to denote the widths, Either change the width to the actual width(in pixels),and then ensure the sum of all the template fields and bound fields are equal, or change the template field widths to percentages and ensure it totals to 100.
Consider that total width of your Grid view is 100% then you can assign proportional percentages to each columns(Please note, Sum of percentages of the TemplateField will not exceed 100). Another thing have to be noticed is, you have to set both HeaderStyle-Width and ItemStyle-Width while setting the width of the column. For example:
<asp:TemplateField HeaderText ="ID" HeaderStyle-ForeColor="White" HeaderStyle-Width="10%" ItemStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text=" ID" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
By doing like this you are setting the width of the ID column to 10% of the actual width of the Grid
The BoundField displays all content in a table cell and therefore the cell will expand as needed. The TemplateField will also be rendered as a cell BUT it contains a div which limits the width of any contents.
Example with code
I have written below lines of code in order to hide and show column in gridview based on the condition.
<asp:TemplateField HeaderText="FirstName" Visible='<%# Eval("FirstName") != null ? true:false %>'>
<ItemTemplate>
<asp:Label ID="lblFirstName" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
It's not working!
Update in code as below :
<asp:TemplateField HeaderText="FirstName" Visible='<%= !string.IsNullOrEmpty(Eval("FirstName")) ? "true" : "false" %>'>
<ItemTemplate>
<asp:Label ID="lblFirstName" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Edit
<asp:TemplateField HeaderText="FirstName" Visible='<%# !string.IsNullOrEmpty(Eval("FirstName")) ? "true" : "false" %>'>
<ItemTemplate>
<asp:Label ID="lblFirstName" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Grid View
<asp:GridView ID="GridDisplay" runat="server" AutoGenerateColumns="False" BorderStyle="Groove"
BorderWidth="1px" BorderColor="ActiveCaptionText" Width="100%" EmptyDataText="No Record Found"
AllowPaging="True" OnPageIndexChanging="GridDisplay_PageIndexChanging" AllowSorting="True"
OnRowEditing="GridDisplay_RowEditing" OnRowDeleting="GridDisplay_RowDeleting"
CssClass="listbooking ListingTable">
<Columns>
<asp:TemplateField HeaderText="Booking Code">
<ItemTemplate>
<%# Eval("id")%>
</ItemTemplate>
<HeaderStyle Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Property Code">
<ItemTemplate>
<%# Eval("property_id")%>
</ItemTemplate>
<HeaderStyle Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%# Eval("sales_username")%>
</ItemTemplate>
<HeaderStyle Width="18%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
i am trying to hide 2 columns(name).
During Binding the grid data
this.GridDisplay.Columns[2].Visible = false;
i want edit and delete button on the right side of the gridview not
at left side of grid. for user friendly manipulation of gridview.
how to show buttons at right side of my grid view?
<asp:GridView ID="GvAllTasks" runat="server" AutoGenerateColumns="false"
AutoGenerateEditButton="true" AutoGenerateDeleteButton="true"
CssClass="table table-hover table-bordered"
onrowcancelingedit="GvAllTasks_RowCancelingEdit"
onrowdeleting="GvAllTasks_RowDeleting"
onrowediting="GvAllTasks_RowEditing" onrowupdating="GvAllTasks_RowUpdating" ShowHeaderWhenEmpty="True" EmptyDataText="No records Found">
you need to set AutoGenerateColumns property false and create the required columns for the grid using property within the html source of the grid in whatever order you want. The columns can be pre defined columns like CheckBoxField, ImageField etc. or templatecolumns. The following example shows creating a grid with edit and delete buttons on right for a table with name DEPT having three columns DEPTNO, DNAME and LOC.
<asp:GridView ID="GvDept" runat="server" AutoGenerateColumns="False"
ShowFooter="true"style="z-index: 1; left: 145px; top: 22px;position:
absolute; height: 191px; width: 756px;font-family: 'Arial Black';
font-size: large" EnableViewState="False">
<Columns>
<asp:TemplateField HeaderText="Deptno">
<ItemTemplate>
<asp:Label ID="LblDno" runat="server"
Text='<%# Eval("Deptno") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dept Name">
<ItemTemplate>
<asp:Label ID="LblDname" runat="server"
Text='<%# Eval("Dname") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location">
<ItemTemplate>
<asp:Label ID="LblLoc" runat="server"
Text='<%# Eval("Loc") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<asp:LinkButton ID="LnkEdit" runat="server" Text="Edit"
CommandName="Edit" />
<asp:LinkButton ID="LnkDelete" runat="server"
Text="Delete" CommandName="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
for adding edit and delete buttons left side of ur gridview add
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
in your columns after your template field
CssClass="table table-hover table-bordered"
onrowcancelingedit="GvAllTasks_RowCancelingEdit"
onrowdeleting="GvAllTasks_RowDeleting"
onrowediting="GvAllTasks_RowEditing" onrowupdating="GvAllTasks_RowUpdating" ShowHeaderWhenEmpty="True" EmptyDataText="No records Found">
<%-- AutoGenerateEditButton="true"--%>
<%-- AutoGenerateDeleteButton="true" --%>
<Columns>
<asp:TemplateField HeaderText="Task Id">
<ItemTemplate>
<asp:HiddenField ID="HiddTaskid" runat="server" Value='<%# Eval("task_Id") %>' />
<%#Eval("task_Id")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task Name">
<ItemTemplate>
<%#Eval("task_Name")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Assigned To">
<ItemTemplate>
<%#Eval("task_Employee_Name")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Project Name">
<ItemTemplate>
<%#Eval("task_Project_Title")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task Status">
<ItemTemplate>
<%#Eval("task_Status")%>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lbl_Status" runat="server" Text='<%#"Status : " + Eval("task_Status") %>'></asp:Label>
<asp:DropDownList ID="Gv_DdlStatus" runat="server">
<asp:ListItem Text="-Change Status-" Value="0"></asp:ListItem>
<asp:ListItem Text="Reviewed" Value="1"></asp:ListItem>
<asp:ListItem Text="InProgress" Value="1"></asp:ListItem>
<asp:ListItem Text="Completed" Value="2"></asp:ListItem>
<asp:ListItem Text="Stopped" Value="3"></asp:ListItem>
</asp:DropDownList>
<asp:HiddenField ID="hiddstatusId" runat="server" Value='<%# Eval("task_Status") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task Start dt">
<ItemTemplate>
<%#Eval("task_StartDate")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task Completed dt">
<ItemTemplate>
<%#Eval("TaskCompletedDt")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtTaskCompletedDt" runat="server" Text='<%# Eval("TaskCompletedDt") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Assigned By">
<ItemTemplate>
<%#Eval("AssignedBy")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Comments">
<ItemTemplate>
<%#Eval("comment")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtComments" runat="server" Text='<%# Eval("comment") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
I have two Template fields in a datagrid whose values I need to pass in a query string in a Hyperlink field in the datagrid.
The first value I need is the Nest Number. The second is the Park Name.
How do I put those values in the querystring?
Here is the start of the gridview with the two Templates:
<asp:GridView ID="NestListGrid" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" Width="95%" OnRowCancelingEdit="NestListGrid_RowCancelingEdit" OnRowEditing="NestListGrid_RowEditing" OnRowUpdating="NestListGrid_RowUpdating" >
<Columns>
<asp:BoundField DataField="NestID" Visible="False" />
<asp:TemplateField HeaderText="Nest Nbr">
<EditItemTemplate>
<asp:TextBox ID="NestNumber_tbx" Width="100px" MaxLength="10" runat="server" Text='<%# Bind("NestNumber") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="NestNumber_lbl" runat="server" Text='<%# Bind("NestNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Park">
<EditItemTemplate>
<asp:DropDownList ID="Park_ddl" runat="server" DataSourceID="ParkIDNameGridViewDDL_SDS"
DataTextField="ParkName" DataValueField="ParkID" SelectedValue='<%# Bind("ParkID") %>' >
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="ParkName_lbl" runat="server" Text='<%# Bind("ParkName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
...etc...
Here is the Hyperlink Query String later in the datagrid:
<asp:HyperLinkField Text="Nest Info" DataNavigateUrlFields="NestID" DataNavigateUrlFormatString="NestInfoUser.aspx?NestID={0}&NestNumber={0}&ParkName={0}" />
-
You can use with comma.
<asp:HyperLinkField Text="Nest Info" DataNavigateUrlFields="NestID,ParkName"
DataNavigateUrlFormatString="NestInfoUser.aspx?NestNumber={0}&ParkName={1}" />
I have a Master Page which contain a Script Manager.In a child page i have a scrollable gridview with checkbox and some textboxes
<div id="grdScr" style ="width:130%; overflow:auto" align="center" >
<asp:GridView ID="dgvBill" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" ForeColor="Black" GridLines="Horizontal" PageSize="100"
Width="150%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="True"
oncheckedchanged="chkSelect_CheckedChanged" />
<asp:Label ID="lblVendCd" runat="server" Text='<%# Eval("vend_cd") %>'
Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Bill date">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("bill_dt") %>'></asp:Label>
<asp:Label ID="lbltrid" runat="server" Text='<%# Eval("tr_id") %>'
Visible="False"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Bill no">
<ItemTemplate>
<asp:Label ID="lblBillNO" runat="server" Text='<%# Eval("bill_no") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Vendor">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("vend_nm") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Supplier">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("supplier") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Driver">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("driver") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Vechicle Type">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("comm_nm") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Vehicle No">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Eval("veh_no") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Payable Amount">
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Eval("payable") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cash">
<ItemTemplate>
<asp:TextBox ID="txtCashGrid" runat="server" AutoPostBack="True"
Enabled="False" ontextchanged="txtCashGrid_TextChanged"
style="text-align: right" Width="75px" onkeypress="return isNumberKey(event)">0.00</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cheque">
<ItemTemplate>
<asp:TextBox ID="txtChequeGrid" runat="server" AutoPostBack="True"
Enabled="False" ontextchanged="txtChequeGrid_TextChanged"
style="text-align: right" Width="75px" onkeypress="return isNumberKey(event)">0.00</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Bank">
<ItemTemplate>
<asp:TextBox ID="txtBankNameGrid" runat="server" Width="174px"
AutoPostBack="True" ontextchanged="txtBankNameGrid_TextChanged"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cheque No">
<ItemTemplate>
<asp:TextBox ID="txtChqNoGrid" runat="server" Width="75px" AutoPostBack="True"
ontextchanged="txtChqNoGrid_TextChanged"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cheque Date">
<ItemTemplate>
<asp:TextBox ID="txtChDateGrid" runat="server" AutoPostBack="True"
EnableTheming="True" Width="97px"
ontextchanged="txtChDateGrid_TextChanged"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="txtChDateGrid_TextBoxWatermarkExtender"
runat="server" Enabled="True" TargetControlID="txtChDateGrid"
WatermarkText="dd-MMM-yyyy">
</cc1:TextBoxWatermarkExtender>
<cc1:CalendarExtender ID="txtChDateGrid_CalendarExtender" runat="server"
Enabled="True" Format="dd-MMM-yyyy" TargetControlID="txtChDateGrid">
</cc1:CalendarExtender>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White"
HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="#CCCCCC" HorizontalAlign="Center" />
<RowStyle HorizontalAlign="Center" />
</asp:GridView>
</div>
My gridview is inside an update panel. The textboxes are doing some mathematical calculations in side the gridview in their TextChange Event and autopostback is true for them.
Whenever I am pressing tab for moving the cursor to the next textbox the page gets postbacked and the scroll position is not maintained. How will I solve this?