how to write grid view in html table? - c#

I have this grid view and I want to write it as html table but I don't know how
I want to write it in ( table ,thead, td and tr ) tags . I want to know how to write it in html table
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" EnableSortingAndPagingCallbacks="false"
BackColor="White" BorderColor="#999999"
ViewStateMode="Enabled" width="713px" CellPadding="3"
HorizontalAlign="Center" AllowSorting="True" OnPageIndexChanging="GridView1_PageIndexChanging"
BorderStyle="Solid" BorderWidth="1px" ForeColor="Black" ShowFooter="True"
GridLines="Vertical" AutoGenerateColumns="False" PageSize="20" onrowdatabound="GridView1_RowDataBound"
Height="16px" >
<Columns>
<asp:TemplateField HeaderText="الرصيد">
<ItemTemplate>
<asp:Label runat="server" ID="lblTotal" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="مدين">
<ItemTemplate>
<div style="padding:0 0 5px 0"> <asp:Label ID="debit" runat="server" Text='<%# (Eval("stat_flag").ToString() =="d" ) ? string.Format("{0:0.000}",float.Parse(Eval("stat_amount").ToString())): "0.00" %>'></asp:Label></div>
<div><asp:Label ID="lblGrandTotal" runat="server" /></div>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="totallblDebAmount" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="دائن">
<ItemTemplate>
<div style="padding:0 0 5px 0"><asp:Label ID="credit"
runat="server" Text='<%# (Eval("stat_flag").ToString() =="c" ) ?
string.Format("{0:0.000}",float.Parse(Eval("stat_amount").ToString())):
"0.00" %>'></asp:Label></div>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="totallblCredAmount" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="stat_desc"
HeaderText="البيان" ItemStyle-Font-
Size="Small">
<ItemStyle Font-Size="Small"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="trans_name"
HeaderText=" نوع السند " ItemStyle-Font-
Size="Small">
<ItemStyle Font-Size="Small"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="serial"
HeaderText=" رقم السند " ItemStyle-Font-
Size="Small">
<ItemStyle Font-Size="Small"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="التاريخ">
<ItemTemplate>
<asp:Label ID="date" runat="server" Text='<%#Eval("stat_date" ,"{0:dd/MM/yyyy}" )%>'> ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<div style="padding:0 0 5px 0"><asp:Label ID="Label5" Text="اجمالي الصفحة
" runat="server" /></div>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#336699" Font-
Bold="True" ForeColor="White" HorizontalAlign="right" />
<RowStyle BorderColor="Black" BorderStyle="Solid"
BorderWidth="1px" />
<AlternatingRowStyle BackColor="#DDDDDD" />
<HeaderStyle BackColor="#aaaaaa" Font-Bold="True"
HorizontalAlign="Center"
VerticalAlign="Middle" ForeColor="Black"
BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"/>
<PagerStyle BackColor="#999999" ForeColor="Blue"
HorizontalAlign="Left" Font-Bold="True"
Font-Underline="False" BorderStyle="Solid"
BorderWidth="1px" BorderColor="#666666" />
</asp:GridView>
for an example I want to write it in html format like this format
<TABLE CELLPADDING=6>
<THEAD>
<TR> <TH>Weekday</TH> <TH>Date</TH> <TH>Manager</TH> <TH>Qty</TH> </TR>
</THEAD>
<TBODY>
<TR> <TD>Mon</TD> <TD>09/11</TD> <TD>Kelsey</TD> <TD>639</TD> </TR>
<TR> <TD>Tue</TD> <TD>09/12</TD> <TD>Lindsey</TD> <TD>596</TD> </TR>
<TR> <TD>Wed</TD> <TD>09/13</TD> <TD>Randy</TD> <TD>1135</TD> </TR>
<TR> <TD>Thu</TD> <TD>09/14</TD> <TD>Susan</TD> <TD>1002</TD> </TR>
<TR> <TD>Fri</TD> <TD>09/15</TD> <TD>Randy</TD> <TD>908</TD> </TR>
<TR> <TD>Sat</TD> <TD>09/16</TD> <TD>Lindsey</TD> <TD>371</TD> </TR>
<TR> <TD>Sun</TD> <TD>09/17</TD> <TD>Susan</TD> <TD>272</TD> </TR>
</TBODY>
<TFOOT id="table_footer">
<TR> <TH ALIGN=LEFT COLSPAN=3>Total</TH> <TH>4923</TH> </TR>
</TFOOT>
</TABLE>
</body>
</html>

Maybe you could create your GridView, run your project and then right click on the browser screen and Inspect Element. Then, you will see the generated Html code.
Or you can visit this website that has an example that can help you: Export Gridview To HTML File Using ASP.Net C#.

Related

How to populate and display a child gridview in asp.net

I am working on an asp.net C# project. I have created a nested gridview (gv). The primary key for the child gv data is the DatakeyNames value of the parent gv. The DatakeyNames is set to SchemeId. The problem I am having is that if I populate the child gv from code-behind using the DatakeyNames's SchemeId then the child gv is not displayed. I tried to get the value using a hiddenfield withing a ItemTemplate. The problem with this is that an empty column is displayed at the end of the grid view. To avoid this, I tried to add the hiddenfield as part of another ItemTemplate, then also the child gv is not displayed. Then I tried visible=False on the ItemTemplate containing the hiddenfield, but still an empty column was displayed. This is very strange. Any help is greatly appreciated.
<asp:GridView ID="grdParent" BackColor="#f1f1f1" CellPadding="0" CellSpacing="0"
AutoGenerateColumns=false DataKeyNames="SchemeId"
runat="server" OnRowDataBound="grdParent_RowDataBound" Width="80%" OnRowCreated="grdParent_OnRowCreated" >
<AlternatingRowStyle BackColor="White" />
<RowStyle Font-Size="12px" VerticalAlign="Top" Height="30px" />
<HeaderStyle BackColor="#57668A" ForeColor="#d6d6d6" Font-Bold="True" Font-Size="14px" Height="35px"/>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:expandcollapse('div<%# Eval("PlanedScheduleId") %>', 'one');">
<img id="imgdiv<%# Eval("PlanedScheduleId") %>" alt="Click to show/hide Orders for Customer <%# Eval("PlanedScheduleId") %>" width="10px" height="10px" src="images/Minus-26.png"/>
</a>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Date" SortExpression="Date">
<ItemTemplate>
<asp:Label ID="lblDate" Text='<%# Eval("Date") %>' runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate >
<asp:HiddenField ID="hfSchemeId" runat="server" Value='<%# Eval("SchemeId") %>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div class="divBackground" id="div<%# Eval("PlanedScheduleId") %>" style="position:relative;OVERFLOW: auto; WIDTH: 97%;padding:0px 20px 20px 31px" >
<asp:GridView ID="grdChild" BackColor="White" Width=100% Font-Size=X-Small
AutoGenerateColumns=false Font-Names="Verdana" runat="server" DataKeyNames="SchemeId"
BorderStyle=Double BorderColor="#57668A">
<RowStyle Font-Size="12px" VerticalAlign="Top" height="25px" />
<HeaderStyle BackColor="#B0C4DE" ForeColor="Black" Font-Bold="True" Font-Size="12px" Height="30px"/>
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Start Date" >
<ItemTemplate>
<asp:Label ID="lblOrderID" Text='<%# Eval("StartDate") %>' runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Start Time">
<ItemTemplate><%# Eval("StartTime")%></ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="End Date" >
<ItemTemplate>
<asp:Label ID="Label2" Text='<%# Eval("EndDate") %>' runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="End Time">
<ItemTemplate><%# Eval("EndTime")%></ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void grdParent_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
if (e.Row.RowType == DataControlRowType.DataRow)
{
int SchemeId = Convert.ToInt32(grdParent.DataKeys[e.Row.RowIndex].Values[0]);
GridView gv = new GridView();
gv = (GridView)row.FindControl("grdChild");
gv.DataSource = ChildDataSource(SchemeId.ToString());
gv.DataBind();
}
}

gridview edit mode is not getting fired on single click

I want to edit the record in gridview on single click. My gridview is placed inside update panel.
There is a search textbox given and when I type anything in search textbox "txt_Search_TextChanged" event is fired and that text is searched in database and that particular record is fetched and bind to the grid.
Now my problem is: If I click on edit button of grid without searching, then event is fired. But if I search any record and then I click on edit button, it takes 2 click to give result. I have written a script for textbox which is as follows:
enter code here
<script>
function RefreshUpdatePanel() {
__doPostBack('<%= txt_Search.ClientID %>', '');
};
below is aspx code
<table width="100%">
<tr>
<td align="center">
<div style="border-width: 2px; border-style: solid; border-color: #FDAC4C; width: 95%; border-radius: 10px;">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:GridView ID="grd_Master" ShowFooter="false" runat="server" Width="98%" AllowPaging="true" PagerStyle-CssClass="paging"
OnPageIndexChanging="grd_Master_PageIndexChanging"
PageSize="8" AutoGenerateColumns="False" BorderWidth="0" BorderStyle="Solid" BorderColor="#FDAC4C" OnRowEditing="grd_Master_RowEditing" ShowHeaderWhenEmpty="true">
<AlternatingRowStyle BackColor="#FFFFFF" Height="30px" BorderStyle="Dotted" BorderWidth="1"
BorderColor="#DDDDDD" />
<RowStyle BackColor="#FFF0DD" Height="30px" BorderStyle="Dotted" BorderWidth="1"
BorderColor="#DDDDDD" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Serial No.<br />
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemStyle HorizontalAlign="Right" Width="10%" CssClass="grdrow"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblSRNO" runat="server" Style="padding-right: 50px" Text='<%#Container.DataItemIndex+1 %>'></asp:Label>
<asp:Label ID="Cooling_Code" runat="server" Visible="false" Text='<% #Bind("Cool_Code")%>'></asp:Label>
<asp:Label ID="lblProdGrpCode" runat="server" Style="padding-left: 100px" Text='<% #Bind("Prod_Grp_Code")%>' Visible="false"></asp:Label>
<asp:Label ID="lblSubProdGrpCode" runat="server" Style="padding-left: 100px" Text='<% #Bind("Sub_Prod_Code")%>' Visible="false"></asp:Label>
<asp:Label ID="lblMakeCode" runat="server" Style="padding-left: 100px" Text='<% #Bind("Make_Code")%>' Visible="false"></asp:Label>
<asp:Label ID="lblRegerCode" runat="server" Style="padding-left: 100px" Text='<% #Bind("Refg_Code")%>' Visible="false"></asp:Label>
<asp:Label ID="lblCompressorCode" runat="server" Style="padding-left: 100px" Text='<% #Bind("Comp_Code")%>' Visible="false"></asp:Label>
<asp:Label ID="lblFilePath" runat="server" Visible="false" Style="padding-left: 100px" Text='<% #Bind("Document_Path")%>'></asp:Label>
</ItemTemplate>
<HeaderStyle CssClass="grdheader" Width="10%" />
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Cooling Name
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemStyle HorizontalAlign="Left" Width="20%" CssClass="grdrow"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblCoolingName" runat="server" Style="padding-left: 10px" Text='<% #Bind("Cool_Name")%>'></asp:Label>
</ItemTemplate>
<HeaderStyle CssClass="grdheader" Width="20%" />
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Short Name
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="grdheader" Width="15%"></HeaderStyle>
<ItemStyle HorizontalAlign="Left" Width="15%" CssClass="grdrow"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblCoolingShortName" runat="server" Style="padding-left: 10px" Text='<% #Bind("Cool_Short_Name")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Cooling Description
</HeaderTemplate>
<ItemStyle HorizontalAlign="left" Width="45%" CssClass="grdrow"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblCoolingDescr" runat="server" Style="padding-left: 10px" Text='<% #Bind("Cool_Descr")%>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="grdheader" Width="45%"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Action<br />
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="grdheader" Width="10%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="10%" CssClass="grdrow"></ItemStyle>
<ItemTemplate>
<asp:ImageButton ID="imgbtnEdit" runat="server" ImageUrl="~/images/Edit.png" Width="20px" ToolTip="Edit" CommandName="Edit" Height="20px" />
<asp:ImageButton ID="ImageDelete" runat="server" ImageUrl="~/images/trash1.png" ToolTip="Delete" OnClick="ImageDelete_Click" Width="25px" Height="20px" OnClientClick="return confirmDelete()" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle HorizontalAlign="Left" BorderWidth="0" BorderStyle="None" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txt_Search" />
<asp:PostBackTrigger ControlID="grd_Master" />
</Triggers>
</asp:UpdatePanel>
</div>
</td>
</tr>
</table>
Below is cs code for rowediting
protected void grd_Master_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
tab0.Enabled = false;
tab1.Enabled = true;
grd_Master.EditIndex = e.NewEditIndex;
GridViewRow rw = (GridViewRow)grd_Master.Rows[e.NewEditIndex];
Label CoolingCode = (Label)rw.FindControl("Cooling_Code");
Label ProdgrpCode = (Label)rw.FindControl("lblProdGrpCode");
Label SubProdCode = (Label)rw.FindControl("lblSubProdGrpCode");
Label MakeCode = (Label)rw.FindControl("lblMakeCode");
Label ReferCode = (Label)rw.FindControl("lblRegerCode");
Label CompressoreCode = (Label)rw.FindControl("lblCompressorCode");
Label CoolingName = (Label)rw.FindControl("lblCoolingName");
Label CoolingName_Short = (Label)rw.FindControl("lblCoolingShortName");
Label CoolingName_Desc = (Label)rw.FindControl("lblCoolingDescr");
Label lblFilePath = (Label)rw.FindControl("lblFilePath");
txtCoolType.Text = CoolingName.Text.Trim();
txtCoolTypeShortname.Text = CoolingName_Short.Text.Trim();
txtCoolTypeDescrip.Text = CoolingName_Desc.Text.Trim();
ddlProdGrp.SelectedValue = ProdgrpCode.Text;
ddlSubProd.SelectedValue = SubProdCode.Text;
ddlMake.SelectedValue = MakeCode.Text;
ddlCompressor.SelectedValue = CompressoreCode.Text;
ddlRefe.SelectedValue = ReferCode.Text;
btnsave.Text = "Update";
ViewState["CoolingCode"] = CoolingCode.Text;
TabContainer_Item.ActiveTabIndex = 1;
Session["CoolingCode"] = CoolingCode.Text;
this.fu1.BindGridDoc();
}
catch (Exception ex)
{
Master.ErrorMessage(ex.Message);
}
}
protected void txt_Search_TextChanged(object sender, EventArgs e)
{
try
{
DataSet ds = gn.ExecuteDataset("Search_CoolingType", txt_Search.Text.Trim());
ViewState["CoolingTypeData"] = ds.Tables[0];
if (ds.Tables[0].Rows.Count == 0)
{
FillEmptyGrid();
}
else
{
grd_Master.DataSource = ds;
grd_Master.DataBind();
}
}
catch (Exception ex)
{
Master.ErrorMessage(ex.Message);
}
}
You need to make sure that the grid has focus. The initial click is likely just setting focus on the grid, and then it sees the second click as starting your edit.
A simple ActiveControl = grd_Master; at the end of the txt_Search_TextChanged event should do the trick.

Printing an aspx file in Asp.net

I have used the following code to print an HTML DIV Contents & it works fine, but when I am using an Ajax Control in an Aspx page then it gives me an error message, i.e:
"Extender control 'CalendarExtender2' is not a registered extender
control. Extender controls must be registered using
RegisterExtenderControl() before calling RegisterScriptDescriptors().
Parameter name: extenderControl"
Here is my C# code
protected void BtnPrint_Click(object sender, EventArgs e)
{
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
Page pg = new Page();
pg.EnableEventValidation = false;
HtmlForm frm = new HtmlForm();
pg.EnableEventValidation = false;
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(divContent);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.End();
}
Here is my Aspx code
<%# Page Title="" Language="C#" MasterPageFile="~/Masters/TSAMaster.master" AutoEventWireup="true"
EnableEventValidation="false" Theme="skinFiles" CodeFile="AdminHome.aspx.cs"
Inherits="Masters_Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script type="text/javascript">
function ValidateDate() {
isValidDate = ValidateDate();
if (!isValidDate) {
return false;
}
else {
return true;
}
}
function ValidateDate() {
var Fdate = document.getElementById('ctl00_ContentPlaceHolder1_txtFDate').value;
var Tdate = document.getElementById('ctl00_ContentPlaceHolder1_txtTDate').value;
var todaysDate = formatDate(new Date(), 'dd/MM/yyyy');
var isValidDate = true;
var flag;
if (trim(Fdate) != 0 || trim(Tdate) != 0) {
if (!isDate(Fdate, 'dd/MM/yyyy')) {
alert("Please select valid From Date enter into (dd/MM/yyyy) format");
document.getElementById('ctl00_ContentPlaceHolder1_txtFDate').focus();
return false;
}
if (!isDate(Tdate, 'dd/MM/yyyy')) {
alert("Please select valid To Date enter into (dd/MM/yyyy) format ");
document.getElementById('ctl00_ContentPlaceHolder1_txtFDate').focus();
return false;
}
if (((compareDates(Fdate, 'dd/MM/yyyy', Tdate, 'dd/MM/yyyy')) == 1)) {
alert("To date cannot be less than From Date ");
return false;
}
return true;
}
}
function trim(str) {
return str.replace(/^[\s]+/, '').replace(/[\s]+$/, '').replace(/[\s]{2,}/, ' ');
}
</script>
<ajaxToolkit:ToolkitScriptManager runat="Server" EnableScriptGlobalization="true"
EnableScriptLocalization="true" ID="ScriptManager1" />
<center>
<div class="divContainPage" id="divContent" runat="server">
<table id="tblHead" runat="server">
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="DueDate Report" Font-Bold="True" Font-Names="Verdana"
Font-Size="Large" ForeColor="#C80000"></asp:Label>
<br />
<br />
<table id="tbl1" runat="server" style="width: 823px">
<tr>
<td>
Select Payment Mode:
</td>
<td>
<asp:DropDownList ID="ddlPayMode" runat="server" CssClass="DropDown" Width="85px">
<asp:ListItem>--Select--</asp:ListItem>
<asp:ListItem>Cash</asp:ListItem>
<asp:ListItem>Cheque</asp:ListItem>
</asp:DropDownList>
</td>
<td>
From Date:
</td>
<td>
<asp:TextBox ID="txtFDate" runat="server" Width="110px"></asp:TextBox>
<asp:ImageButton ID="imgCalendar" runat="server" ImageUrl="~/Images/calendar.png"
TabIndex="1" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtFDate"
Format="dd/MM/yyyy" PopupPosition="BottomRight" PopupButtonID="imgCalendar" />
</td>
<td>
To Date:
</td>
<td>
<asp:TextBox ID="txtTDate" runat="server" Width="110px"></asp:TextBox>
<asp:ImageButton ID="imgCalendar1" runat="server" ImageUrl="~/Images/calendar.png"
TabIndex="2" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender3" runat="server" TargetControlID="txtTDate"
Format="dd/MM/yyyy" PopupPosition="BottomRight" PopupButtonID="imgCalendar1" />
</td>
<td>
<asp:Button ID="btnGo" runat="server" Text="Go" OnClick="btnGo_Click" OnClientClick="return ValidateDate();" />
</td>
<td>
<asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="btnReset_Click" Width="47px" />
</td>
</tr>
</table>
<table style="width: 600px" runat="server" id="tblone">
<tr>
<td>
<asp:GridView ID="grdStudentInfo" runat="server" SkinID="Professional" DataKeyNames="StudentID"
Width="800px" AllowSorting="True" AutoGenerateColumns="False" BackColor="#DEBA84"
BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
OnSorting="grdStudentInfo_sorting" AllowPaging="True" OnPageIndexChanging="grdStudentInfo_PageIndexChanging"
OnRowCommand="grdStudent_RowCommand">
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<Columns>
<asp:BoundField HeaderText="Name" DataField="FirstandLastName" SortExpression="FirstandLastName">
<ItemStyle HorizontalAlign="left" Width="100px" />
<HeaderStyle HorizontalAlign="left" Width="100px" />
</asp:BoundField>
<asp:BoundField HeaderText="Amount Due" DataField="FirstInstallmentFee" SortExpression="FirstInstallmentFee">
<ItemStyle HorizontalAlign="left" Width="100px" />
<HeaderStyle HorizontalAlign="left" Width="100px" />
</asp:BoundField>
<asp:BoundField HeaderText="Payment Mode" DataField="FirstInsMode" SortExpression="FirstInsMode">
<ItemStyle HorizontalAlign="left" Width="100px" />
<HeaderStyle HorizontalAlign="left" Width="100px" />
</asp:BoundField>
<asp:BoundField HeaderText="Bank Name" DataField="FirstBankName" SortExpression="FirstBankName">
<ItemStyle HorizontalAlign="left" Width="200px" />
<HeaderStyle HorizontalAlign="left" Width="200px" />
</asp:BoundField>
<asp:BoundField HeaderText="Cheque Number" DataField="FirstChequeNumber" SortExpression="FirstChequeNumber">
<ItemStyle HorizontalAlign="left" Width="200px" />
<HeaderStyle HorizontalAlign="left" Width="200px" />
</asp:BoundField>
<asp:BoundField HeaderText="Due Date" DataField="FirstInstallmentDate" SortExpression="FirstInstallmentDate">
<ItemStyle HorizontalAlign="left" Width="200px" />
<HeaderStyle HorizontalAlign="left" Width="200px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CommandName="editStudent" Text="Edit"
CommandArgument='<%#Eval("StudentID")%>'></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="200px" />
<HeaderStyle HorizontalAlign="Left" Width="200px" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</td>
</tr>
</table>
<table id="tbl3" runat="server">
<tr style="height: 30px;">
<td>
<asp:Button ID="btnExport2PDF" runat="server" Text="Export To PDF" OnClick="btnExport2PDF_Click" />
</td>
<td>
<asp:Button ID="btnExport2XLS" runat="server" Text="Export To XLS" OnClick="btnExport2XLS_Click" />
<asp:HiddenField ID="hidSort" runat="server" Value="1" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</center>
If I use frm.Controls.Add(tblOne) instead of frm.Controls.Add(divContent) then it works fine because tblone doesn't have an Ajax Control. But divContent has both the table as well as Ajax Controls, and it throws the above exception. I have tried many options like overriding OnInit and OnPreRender but doesn't work for me.
It could be due to the placement of ToolkitScriptManager in your code. See if this resolves your problem:
Error: Extender controls may not be registered before PreRender
Finally i have resolved this problem by using JavaScript code & it works better for me, i would like to thanks for all who gives their valuable time & feedback.
The code is here :
<script>
function Panel1() {
var panel = document.getElementById("<%=printablediv.ClientID %>");
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head><title>newTable</title>');
printWindow.document.write('</head><body >');
printWindow.document.write(panel.innerHTML);
printWindow.document.write('</body></html>');
printWindow.document.close();
setTimeout(function() {
printWindow.print();
printWindow.close();
}, 1000);
return false;
}
</script>

Gridview Calendar Extender get date

I have a GridView which allows users to enter data using a EmptyDataTemplate. There is a text box having a calendarextender. I want to get the date entered (format MM/dd/yyyy) and pass it to the database.
Please let me know how to do it.
My code:
<asp:GridView ID="GV_Rotl_Asgt" runat="server" EnableModelValidation="True"
BackColor="White" BorderColor="#999999" BorderStyle="None"
BorderWidth="1px" CellPadding="3" Font-Names="Arial"
Font-Size="8pt" GridLines="Vertical"
AllowSorting="True" EnableSortingAndPagingCallbacks="True" AutoGenerateColumns="False"
Width="1196px"
ShowFooter="True" OnRowCommand="GV_RowCommand" DataKeyNames="Emplid">
<FooterStyle BackColor="#CCCCCCC" ForeColor="Black" />
<PagerSettings PageButtonCount="1000" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<Columns>
<asp:TemplateField HeaderText="Action" HeaderStyle-ForeColor="#00349C">
<ItemTemplate>
<asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CommandName="Edit" CssClass="infotitle" /> <br />
<asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="Delete" CssClass="infotitle"/>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" CssClass="infotitle" />
<asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" CssClass="infotitle"/>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton runat="server" ID="Insert" Text="Insert" CommandName="InsertNew" CssClass="infotitle" />
<asp:LinkButton runat="server" ID="Cancel" Text="Cancel" CommandName="CancelNew" CssClass="infotitle" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<table id="NoDatatbl" width="100%" style="margin-right: 0px">
<tr>
<td class="ColumnHead" width="150px">
To Date</td>
<td class="ColumnHead" width="150px">
From Date</td>
<td class="ColumnHead" width="150px">
Rotational Assignment</td>
<td class="ColumnHead" width="150px">
Location</td>
<td class="ColumnHead" width="150px">
</td>
</tr>
</table>
<table id="NoDatatbl1" width="100%" style="margin-right: 0px">
<tr>
<td class="ColumnHead" width="150px">
<asp:TextBox runat="server" ID="NodataToDt" format="MM/dd/yyyy"/>
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="NodataToDt" format="MM/dd/yyyy"/>
</td>
<td class="ColumnHead" width="150px">
<asp:TextBox runat="server" ID="NodatafrmDt" format="MM/dd/yyyy"/>
<asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="NodatafrmDt" format="MM/dd/yyyy"/>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="NodatafrmDt" ControlToCompare="NodataToDt" Operator="GreaterThanEqual"
Display="Dynamic" ErrorMessage="From Date should be greater than To Date"
Type="Date"></asp:CompareValidator>
<asp:ValidatorCalloutExtender ID="CompareValidator1_ValidatorCalloutExtender" runat="server" Enabled="True" TargetControlID="CompareValidator1">
</asp:ValidatorCalloutExtender>
</td>
<td class="ColumnHead" width="150px">
<asp:TextBox runat="server" ID="NodataRotl" /></td>
<td class="ColumnHead" width="150px">
<asp:TextBox runat="server" ID="NodataLoc" /></td>
<td class="ColumnHead" width="150px">
<asp:LinkButton runat="server" ID="LinkButton1" Text="Insert" CommandName="NoDataInsert" CssClass="infotitle" />
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:GridView>
Basically, I want to fetch the values from the NodataToDt & NodatafrmDt textboxes in codebehind and pass the values to my stored procedure.
Thanks
In your code behind:
// Find the 2 text boxes within your GridView control
TextBox toDateTextBox = (TextBox)GV_Rotl_Asgt.FindControl("NodataToDt");
TextBox fromDateTextBox = (TextBox)GV_Rotl_Asgt.FindControl("NodatafrmDt");
// Grab the values out of those text boxes
string toDate = toDateTextBox.Text;
string fromDate = fromDateTextBox.Text;
From there, you can do whatever you need with those two string values.

How to enable a button based on a TextBox in GridView in ASP.Net using JavaScript?

I have a TextBox in the TemplateField of a GridView. And I have one button below the GridView. I want to enable the Button when I enter some text in the TextBox in the GridView. How to do this? I am using ASP.Net and C#.Net.
My Source Code of the GridView:
<table>
<tr>
<td>
<asp:GridView ID="gvQCAttribute" runat="server" AllowPaging="true" AutoGenerateColumns="false"
CellPadding="0" CssClass="datagrid" DataKeyNames="ItemID" EnableTheming="false"
PageSize="10" Width="100%">
<EmptyDataTemplate>
<table border="0" cellpadding="0" cellspacing="1" width="100%">
<tr>
<tr>
<th scope="col">
QC Attribute Name
</th>
<th scope="col">
PO Attribute Value
</th>
<th scope="col">
Negative Tolerance
</th>
<th scope="col">
Positive Tolerance
</th>
<th scope="col">
Remarks
</th>
</tr>
</tr>
</table>
</EmptyDataTemplate>
<SelectedRowStyle CssClass="rowselect" />
<HeaderStyle ForeColor="White" />
<AlternatingRowStyle CssClass="table_oddrow" />
<RowStyle CssClass="table_evenrow" />
<PagerStyle CssClass="pager_style" />
<Columns>
<asp:TemplateField HeaderText="ItemID" Visible="false">
<ItemTemplate>
<asp:Label ID="lblgvItemID" runat="server" Text='<%# Bind("ItemID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="QCAttributeID" Visible="false">
<ItemTemplate>
<asp:Label ID="lblgvQCAttributeID" runat="server" Text='<%# Bind("QCAttributeID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Attribute Name">
<ItemTemplate>
<asp:Label ID="txtQCAttributeName" runat="server" Text='<%# Bind("AttributeName") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="150px" />
<ControlStyle Width="100%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="POAttrubute Value">
<ItemTemplate>
<asp:TextBox ID="txtPOAttributeValue" runat="server" Text='<%# Bind("POAttributeValue") %>'
onkeyup="return EnableButton(this);" ValidationGroup="Modal" onkeypress="return checkNum(event);"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="100px" />
<ControlStyle Width="95%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Negative Tolerance">
<ItemTemplate>
<asp:TextBox ID="txtNegTolerance" runat="server" Text='<%# Bind("NegativeTolerance") %>'
onkeyup="return EnableButton(this);" ValidationGroup="Modal" onkeypress="return checkNum(event);"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="100px" />
<ControlStyle Width="95%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Positive Tolerance">
<ItemTemplate>
<asp:TextBox ID="txtPosTolerance" runat="server" Text='<%# Bind("PositiveTolerance") %>'
onkeyup="return EnableButton(this);" ValidationGroup="Modal" onkeypress="return checkNum(event);"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="100px" />
<ControlStyle Width="95%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Remarks">
<ItemTemplate>
<asp:TextBox ID="txtRemarks" runat="server" Text='<%# Bind("Remarks") %>' onkeyup="return EnableButton(this);"
ValidationGroup="Modal"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="100px" />
<ControlStyle Width="95%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnmdeSave" runat="server" Text="Save" CssClass="ButtonClass" ValidationGroup="Modal"
OnClick="btnmdeSave_Click" />
</td>
</tr>
</table>
use onkeypress or onkeyup event and check whether the textbox is empty.
if not, then make the button enable else disable.
function enableButton(){
if(document.getElementById('txtPOAttributeValue').value != '' && document.getElementById('txtNegTolerance').value != '' && document.getElementById('txtPosTolerance').value != ''){
document.getElementById('buttonId').disabled = false;
}else{
document.getElementById('buttonId').disabled = true;
}
}
Use JQuery
// disabling button
$("#buttonID").attr('disabled','disabled');
$("#textBoxID").keypress(function(){
// enabling button
$("#buttonID").removeAttr('disabled');
});

Categories

Resources