Printing an aspx file in Asp.net - c#

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>

Related

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.

how to write grid view in html table?

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

Can't display male/female for gender in gridview

I have a data field "Gender" (sql data type - bit).
I have created bound the data with if condition to check true-> male otherwise -> female. But it still does not display.
Here is the aspx and code behind code:The gridview shows true/false instead of male/female:
<%# Page Title="Add User" Language="C#" AutoEventWireup="true" CodeFile="adduser.aspx.cs" Inherits="_Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="style.css" type="text/css" rel="Stylesheet" />
<script type="text/javascript">
function confirmDelete() {
return confirm("Do you want to delete this record?");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="toolkit1" runat="server">
</ajax:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table border="0" align="center" cellpadding="2" cellspacing="2" class="maindiv">
<tr><!--Hidden field for EmployeeID reference-->
<td colspan="2"><asp:HiddenField ID="txtHiddenEmpID" Value="0" runat="server" /></td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="name" runat="server" Text="Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtEmpName" runat="server" CssClass="box"></asp:TextBox>
<asp:RequiredFieldValidator Display="None" ID="RequiredFieldValidator1" ErrorMessage="Name is required!"
EnableClientScript="true" SetFocusOnError="true" runat="server" ControlToValidate="txtEmpName"
CssClass="error_msg"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="NameValidator" runat="server" ErrorMessage="Name can not contain numeric or special characters."
ControlToValidate="txtEmpName" ValidationExpression="^[A-Za-z ]*$" CssClass="error_msg"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="Label1" runat="server" Text="Address"></asp:Label>
</td>
<td>
<asp:TextBox ID="addressBox" runat="server" CssClass="box"></asp:TextBox>
<asp:RequiredFieldValidator Display="None" ID="AddressValidator" ErrorMessage="Address is required!"
EnableClientScript="true" SetFocusOnError="true" runat="server" ControlToValidate="addressBox"
CssClass="error_msg"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="Label2" runat="server" Text="DOB"></asp:Label>
</td>
<td>
<asp:TextBox ID="dobBox" runat="server" CssClass="dob_cal box" ReadOnly="false" ></asp:TextBox>
<ajax:CalendarExtender ID="CalenderExtender1" TargetControlID="dobBox" Format="dd/MM/yyyy"
runat="server">
</ajax:CalendarExtender>
<asp:RequiredFieldValidator Display="None" ID="dobValidator" ErrorMessage="DOB is required!"
EnableClientScript="true" SetFocusOnError="true" runat="server" ControlToValidate="dobBox"
CssClass="error_msg"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="Label3" runat="server" Text="Salary"></asp:Label>
</td>
<td>
<asp:TextBox ID="salaryBox" runat="server" CssClass="box" MaxLength="8" ></asp:TextBox>
<asp:RequiredFieldValidator ID="salaryValidate" runat="server" ControlToValidate="salaryBox"
ErrorMessage="Salary is required!" Display="None" CssClass="error_msg" SetFocusOnError="true"
EnableClientScript="true"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="SalaryValidator" runat="server" ErrorMessage="Salary can contain only numeric values."
Display="None" ControlToValidate="salaryBox" ValidationExpression="^[0-9]*$"
CssClass="error_msg"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="gender" runat="server" Text="Gender"></asp:Label>
</td>
<td>
<span>
<asp:RadioButton GroupName="gendergrp" ID="gendermale" runat="server" Text="Male"
Checked="true" /></span><span style="padding-left: 5px;">
<asp:RadioButton GroupName="gendergrp" ID="genderfemale" runat="server" Text="Female"
Checked="false" /></span>
</td>
</tr>
<tr>
<td>
<div style="float: right; margin-right: -70px;">
<asp:Button ID="Button1" runat="server" CssClass="btn" Text="Save" OnClick="Button1_Click" /></div>
</td>
<td>
<div style="float: left; margin-left: 70px;">
<asp:Button ID="CancelBtn" CausesValidation="false" runat="server" CssClass="btn"
Text="Cancel" OnClick="CancelBtn_Click" />
</div>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblError" runat="server" CssClass="error_msg"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
<asp:ValidationSummary ID="valSum" DisplayMode="BulletList" EnableClientScript="true"
HeaderText="Error!" runat="server" CssClass="error_msg" />
</td>
</tr>
</table>
<!--div for data display-->
<div class="data_display">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="EmployeeID" EmptyDataText="There are no data records to display."
GridLines="Horizontal" BackColor="#CCCCCC" BorderColor="White" Font-Bold="False"
Font-Names="Arial" Font-Size="Medium" ForeColor="#666666"
AllowPaging="True" PageSize="5" PagerSettings-Mode="Numeric"
PagerSettings-Position="Bottom"
onpageindexchanging="GridView1_PageIndexChanging"
>
<Columns>
<%-- <asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="EmpID" runat="server" Value='<%# Eval("EmployeeID") %>' />
</ItemTemplate>
</asp:TemplateField>
--%> <asp:BoundField DataField="EmployeeID" HeaderText="Employee ID"
SortExpression="EmployeeID" Visible="true" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="EmployeeName" HeaderText="Name" SortExpression="EmployeeName"
ItemStyle-Width="130px" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="130px" />
</asp:BoundField>
<asp:BoundField DataField="DateOfBirth" HeaderText="DoB" SortExpression="DateOfBirth"
DataFormatString="{0:dd-MM-yyyy}" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="Salary" HeaderText="Salary"
SortExpression="Salary">
<ItemStyle HorizontalAlign="Center" Width="90px" />
</asp:BoundField>
<asp:BoundField DataField="Gender" HeaderText="Gender" ItemStyle-Width="90px"
ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="70px" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="EditBtn" runat="server" Text="Select" CausesValidation="false" OnClick="EditBtn_Click" />
<asp:Button ID="DelBtn" runat="server" Text="Delete" CausesValidation="false" OnClick="DelBtn_Click" OnClientClick="confirmDelete()" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#ffffff" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Gray" Font-Bold="false" ForeColor="White" />
<PagerStyle BackColor="Gray" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<br />
<span style="font-family: Arial; font-size: small; color: Green; font-weight: bold;">
You are viewing page <%=GridView1.PageIndex + 1%> of <%=GridView1.PageCount%>
</span>
</div>
<div>
<asp:Label ID="lblMessage" runat="server"></asp:Label></div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
**code behind:**
#region GridView Functions
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[4].Text == "True")
{
e.Row.Cells[4].Text = "Male";
}
else
{
e.Row.Cells[4].Text = "Female";
}
}
}
#endregion
The gridview Gender column shows true/false instead of male/female.
Thanks!
You need a TemplateField for this. Assuming Male equates to True, this should work:
<asp:TemplateField HeaderText="Gender" SortExpression="Gender">
<ItemTemplate><%# (Boolean.Parse(Eval("Gender").ToString())) ? "Male" : "Female" %></ItemTemplate>
</asp:TemplateField>

Delete Individual row of gridview without deleting from database

I am using Linq-to-SQL in ASP.NET & C#. I want to delete individual row of gridview by click on delete button (i.e. CommandField or TemplateField) with gridTrainingNeed_RowDeleting event.
Here is my code for loading gridview on page load.
int departmentId;
int branchId;
int positionId;
double month;
int levelId;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Initialize();
}
}
public void Initialize()
{
ddlBranch.DataSource = TrainingManager.GetBranchName();
ddlBranch.DataBind();
ddlDepartment.DataSource = DepartmentManager.GetAllDepartments();
ddlDepartment.DataBind();
ddlPosition.DataSource = TrainingManager.GetDesignationName();
ddlPosition.DataBind();
ddlLevel.DataSource = TrainingManager.GetLevelName();
ddlLevel.DataBind();
gridTrainingNeed.DataSource = TrainingManager.GetAllEmployees(departmentId, branchId, positionId, month, levelId).ToList();
gridTrainingNeed.DataBind();
}
Now I am going to keep my design code:
<div class="innerLR">
<div class="seperator bottom" />
<div class="widget">
<div class="widget-head">
<h4 class="heading">
Send Circulation To
</h4>
</div>
<div class="widget-body">
<table class="tableShow" cellpadding="3" cellspacing="0">
<tr>
<td>
<asp:DropDownList ID="ddlBranch" runat="server" DataTextField="Name"
DataValueField="BranchId" Width="170px" AppendDataBoundItems="True"
>
<asp:ListItem Text="---Select Branch---"/>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlDepartment" runat="server" AppendDataBoundItems="True"
DataTextField="Name" Width="170px" DataValueField="DepartmentId">
<asp:ListItem Text="---Select Department---"/>
</asp:DropDownList></td>
<td>
<asp:DropDownList ID="ddlLevel" runat="server" DataTextField="Name"
DataValueField="LevelId" Width="170px" AppendDataBoundItems="True"
>
<asp:ListItem Text="---Select Level---"/>
</asp:DropDownList></td>
<td>
<asp:DropDownList ID="ddlPosition" runat="server" DataTextField="Name"
DataValueField="DesignationId" Width="170px" AppendDataBoundItems="True"
>
<asp:ListItem Text="---Select Position---"/>
</asp:DropDownList></td>
</tr>
<tr>
<td>
<br />
Send Circulation To</td>
<td>
<br />
Month</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="ddlCirculation" runat="server" DataTextField="Name"
DataValueField="PositionId" Width="170px" AutoPostBack="true" AppendDataBoundItems="True"
onselectedindexchanged="ddlCirculation_SelectedIndexChanged">
<asp:ListItem Text="" Value="-1" />
<asp:ListItem Text="All" Value="0" />
<asp:ListItem Text="Must Have Worked For" Value="1" />
</asp:DropDownList></td>
<td>
<asp:TextBox ID="txtMonth" Width="150px" runat="server" Enabled="false"></asp:TextBox></td>
<td>
<asp:Button ID="btnShow" runat="server" Text="Show" onclick="btnShow_Click" /></td>
<td>
</td>
</tr>
</table>
</div>
</div>
<div>
<asp:GridView ID="gridTrainingNeed" runat="server" AutoGenerateColumns="False"
EnableModelValidation="True" CellPadding="4" ForeColor="#333333"
GridLines="None" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="EmployeeId" HeaderText="EID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Branch" HeaderText="Branch" />
<asp:BoundField DataField="Department" HeaderText="Department" />
<asp:BoundField DataField="Level" HeaderText="Level" />
<asp:BoundField DataField="Position" HeaderText="Position" />
<asp:CommandField HeaderText="Delete" ShowCancelButton="False"
ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
</div>
</div>
Thus, I want to delete row one by one with RowDeleting Event from displaying data on gridview not from database.
protected void gridTrainingNeed_RowDeleting(object sender, GridViewDeleteEventArgs e)
{//Row delete code
}
Thank You.
Instead of assigning the DataSource directly like you are doing:
gridTrainingNeed.DataSource = TrainingManager.GetAllEmployees(departmentId, branchId, positionId, month, levelId).ToList();
Store the result in Page level List. Define a page level List like:
//Define List at page/class level
List<Employee> gridList = new List<Employee>();
Then in your method Initialize
gridList = TrainingManager.GetAllEmployees(departmentId, branchId, positionId, month, levelId).ToList();
gridTrainingNeed.DataSource = gridList;
gridTrainingNeed.DataBind();
You need to persist the List<Employee> in memory on PostBack, Use Session/ViewState etc. (See ASP.Net State Management).
Later in your gridTrainingNeed_RowDeleting, get the ID from row or any field that uniquely identify an employee. Query your list and remove that object from the List in memory. Re-assign the DataSource to the modified list and call DataBind.

Play Sound Using Javascript with UpdatePanel

I Have the below Asp.net Code:
the problem is that When Timer Tick Every 30 Second and GridView Filled the javascript code is not executed !! and Sound is not played.
I have also tried SoundPlayer Class but is not working on the Server Side can anyone provide me with a solution ?
<%# Page Language="C#" AutoEventWireup="true" CodeFile="OrdersPage.aspx.cs" Inherits="Orders_" Async="true" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Gazar | Orders Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<link rel="Stylesheet" href="StyleSheet.css" />
<script type="text/javascript">
function ShowProgress() {
document.getElementById('UpdateProgress1').style.display = "inline";
}
</script>
</head>
<body>
<form id="form1" class="center_it" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" EnablePageMethods="true" runat="server"></asp:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<table class="MainTable">
<tr>
<td style="text-align: left;" colspan="2">
<img id="Img2" src="~/images/gazzarlogo.png" alt="GazarBanner" runat="server" class="BannerImage" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="30pt" ForeColor="White"
Text="الطلبـــــات"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="History" CssClass="Buttons" />
</td>
<td>
<asp:Button ID="Exit" Text="خروج" runat="server" OnClick="Exit_Click" CssClass="Buttons" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="GridViewOrders" runat="server" Style="margin-left: auto; margin-right: auto;"
OnRowDataBound="GridViewOrders_RowDataBound" PageSize="30" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="0px" CaptionAlign="Top"
CellPadding="4" ForeColor="Black" HorizontalAlign="Center" EnableModelValidation="True"
GridLines="Vertical" Width="1100px" Font-Names="Tahoma" Font-Size="10pt" Font-Bold="False"
OnRowCommand="GridViewOrders_RowCommand" AutoGenerateColumns="False">
<RowStyle BackColor="#F7F7DE" Wrap="True" />
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#CCCC99" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="Open" ItemStyle-Width="60px">
<ItemTemplate>
<asp:Button ID="ApproveBtn" Text="Open" Width="60" Height="30" runat="server" OnClientClick="ShowProgress()" />
</ItemTemplate>
<ItemStyle Width="70px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" ItemStyle-Width="70px">
<ItemTemplate>
<asp:Label ID="OrderID" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "ID") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="70px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" ItemStyle-Width="150px">
<ItemTemplate>
<asp:Label ID="Name" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Name") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" ItemStyle-Width="300px">
<ItemTemplate>
<asp:Label ID="Address" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Address") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="300px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Number" ItemStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="Number" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Number") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Sent Date" ItemStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="SentDate" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Sent Date") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Recieved Date" ItemStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="RecievedDate" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Recieved Date") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="# Success" ItemStyle-Width="50px">
<ItemTemplate>
<asp:Label ID="SuccessNo" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "# Success") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="# Fake" ItemStyle-Width="50px">
<ItemTemplate>
<asp:Label ID="FakeNo" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "# Fake") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Restaurant" ItemStyle-Width="50px">
<ItemTemplate>
<asp:Label ID="Restaurant" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Restaurant") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Branch" ItemStyle-Width="50px">
<ItemTemplate>
<asp:Label ID="Branch" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Branch") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<div class="container">
<div class="LoadingDiv">
<span class="LoadingLabel">Check Orders ...</span>
<img class="LoadingImg" src="Images/ajax-loader.gif" alt="Loading ..." />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Timer ID="Timer1" runat="server" Interval="30000" OnTick="Timer1_Tick" />
</form>
</body>
</html>
and code behind is:
protected void Timer1_Tick(object sender, EventArgs e)
{
orderDB.LogState("Time Tick");
if (Session["UserID"] != null)
{
orderDB.LogState("Session Alive");
FillDataGrid(int.Parse(Session["UserID"].ToString()));
orderDB.LogState("End fill Grid View");
}
else
{
Response.Redirect("~/login.aspx");
}
}
private void FillDataGrid(int UserID)
{
Orders = orderDB.GetOrdersByUser(UserID);
orderDB.LogState("Select: " + DateTime.Now.ToString() + "\t" + Request.UserHostAddress + "\t" + Session.SessionID + "\t" + Session["UserID"].ToString());
if (Orders == null)
Response.Redirect("~/login.aspx");
DataTable Table = new DataTable();
Table.Columns.Add("ID", System.Type.GetType("System.String"));
Table.Columns.Add("Name", System.Type.GetType("System.String"));
Table.Columns.Add("Address", System.Type.GetType("System.String"));
Table.Columns.Add("Number", System.Type.GetType("System.String"));
Table.Columns.Add("Sent Date", System.Type.GetType("System.String"));
Table.Columns.Add("Recieved Date", System.Type.GetType("System.String"));
Table.Columns.Add("# Success", System.Type.GetType("System.String"));
Table.Columns.Add("# Fake", System.Type.GetType("System.String"));
Table.Columns.Add("Restaurant", System.Type.GetType("System.String"));
Table.Columns.Add("Branch", System.Type.GetType("System.String"));
for (int i = 0; i < Orders.Count; i++)
{
object[] myRow = new object[10];
myRow[0] = Orders[i].GetId();
myRow[1] = Orders[i].GetOwner();
myRow[2] = Orders[i].GetAddress().getAllAddress();
myRow[3] = Orders[i].GetPhoneNumber();
myRow[4] = Orders[i].GetOriginalTime().ToString();
myRow[5] = Orders[i].GetTime().ToString();
myRow[6] = Orders[i].NoOfSuccess; //success Orders;
myRow[7] = Orders[i].NoOfFake; //fake Orders
myRow[8] = Orders[i].GetResName();
myRow[9] = Orders[i].GetBranchName();
Table.Rows.Add(myRow);
}
orderDB.LogState("Table Rows Count: " + Table.Rows.Count);
GridViewOrders.DataSource = Table;
GridViewOrders.DataBind();
string sSelectedAudio = Server.MapPath("home.wav");
if (GridViewOrders.Rows.Count != 0)
{
playSound(sSelectedAudio);
orderDB.LogState("Sound Played: " + GridViewOrders.Rows.Count);
}
else
{
orderDB.LogState("Empty Grid View: " + GridViewOrders.Rows.Count);
}
}
private void playSound(string path)
{
string PlaySound = "<embed src=\"" + path + "\" autostart=\"true\" hidden=\"true\"></embed>";
Response.Write(PlaySound);
}
It could be the Response.Write that's causing the issue. Try using a placeholder control then adding a HtmlGenericControl to it with the markup for the embed tag i.e.
HtmlGenericControl sound = new HtmlGenericControl("<embed src=\"" + path + "\"
autostart=\"true\" hidden=\"true\"></embed>");
ucPlaceHolder.Controls.Add(sound);
Make sure the placeholder control is withing the ContentTemplate of the UpdatePanel that you are using

Categories

Resources