Repeater Not showing any data in asp.net application on hosting server - c#

I am using repeater which works fine on local system but not working when uploaded on web server. And its also working fine when connected to the server from our local code..
The following is the page code and code behind. And repeated contains textbox, dropdown list which loads dynamically at the run time
page code:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="UC_TopicSchedulingNew.ascx.cs" Inherits="Scheduling_UC_TopicSchedulingNew" %>
<%# Register Assembly="XtendedControls" Namespace="XtendedControls" TagPrefix="cc1" %>
<%# Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" TagPrefix="ajax" %>
<%# Register Src="~/SelectPopup/UC_PopupDropdown.ascx" TagName="PopupSelectAny" TagPrefix="PD" %>
<script type="text/javascript">
function pageLoad() {
$('.DatepickerInput').datepicker({ changeMonth: true, changeYear: true, yearRange: '1950:2050', dateFormat: 'dd/mm/yy', showButtonPanel: true });
}
$(document).ready(function () {
$('.DatepickerInput').datepicker({ changeMonth: true, changeYear: true, yearRange: '1950:2050', dateFormat: 'dd/mm/yy', showButtonPanel: true });
});
</script>
<asp:UpdatePanel runat="server" ID="updtsForm">
<ContentTemplate>
<div style="width: 100%; float: left; padding-left: 10px;">
<div style="width: 20%; float: left; padding-left: 10px;">
<div class="editor-label" style="font-weight: bold;">
Branch : <b style="color: Red;">*</b>
</div>
<div class="editor-field">
<asp:TextBox ID="txtBranchs" runat="server" CssClass="txt-drop-down" TabIndex="1"
ReadOnly="true" Width="16px"></asp:TextBox><cc1:XBranch ID="XBranch" runat="server"
TabIndex="-1"></cc1:XBranch>
<ajax:PopupControlExtender ID="PopExBranchs" runat="server" TargetControlID="txtBranchs"
BehaviorID="exbranchClose" PopupControlID="pnlListBranchs" CommitProperty="value"
Position="Bottom" OffsetY="2" />
<asp:HiddenField ID="HFBranchID" runat="server" />
</div>
<br />
<div class="editor-label" style="font-weight: bold;">
Course : <b style="color: Red;">*</b>
</div>
<div class="editor-field">
<asp:TextBox ID="txtCourse" runat="server" CssClass="txt-drop-down" TabIndex="2"
ReadOnly="true" Width="16px"></asp:TextBox><cc1:XCourse ID="XCourse" runat="server"
TabIndex="-1"></cc1:XCourse>
<ajax:PopupControlExtender ID="PopExCourse" runat="server" TargetControlID="txtCourse"
BehaviorID="excourseClose" PopupControlID="pnlListCourse" CommitProperty="value"
Position="Bottom" OffsetY="2" />
<asp:HiddenField ID="HFCourseID" runat="server" />
</div>
<br />
<div class="editor-label" style="font-weight: bold;">
Batch :
</div>
<div class="editor-field">
<asp:TextBox ID="txtBatch" runat="server" CssClass="txt-drop-down" TabIndex="44"
ReadOnly="true" Width="16px"></asp:TextBox><cc1:XTextBox ID="XBatch" runat="server"
TabIndex="-1"></cc1:XTextBox>
<ajax:PopupControlExtender ID="PopExBatch" runat="server" TargetControlID="txtBatch"
BehaviorID="exBatchClose" PopupControlID="pnlListBatch" CommitProperty="value"
Position="Bottom" OffsetY="2" />
<asp:HiddenField ID="HFBatchID" runat="server" Value="0" />
<asp:HiddenField ID="HFBatchClRoom" runat="server" />
</div>
<br />
</div>
<div style="width: 20%; float: left; padding-left: 10px;">
<div class="editor-label" style="font-weight: bold;">
Time :
</div>
<div class="editor-field">
<cc1:XTextBox ID="XTime" runat="server" TabIndex="-1" Width="149px"></cc1:XTextBox>
</div>
<br />
<div class="editor-label" style="font-weight: bold;">
Start Date :
</div>
<div class="editor-field">
<cc1:XTextBox ID="XStartDate" runat="server" TabIndex="-1" Width="149px"></cc1:XTextBox>
</div>
<br />
<div class="editor-label" style="font-weight: bold;">
End Date :
</div>
<div class="editor-field">
<cc1:XTextBox ID="XEndDate" runat="server" TabIndex="-1" Width="149px"></cc1:XTextBox>
</div>
<br />
</div>
<div style="width: 50%; float: left; padding-left: 10px;">
<div class="editor-label" style="font-weight: bold;">
Curriculum :
</div>
<div class="editor-field">
<asp:TextBox ID="txtCurriculum" runat="server" CssClass="txt-drop-down" TabIndex="44"
ReadOnly="true" Width="16px"></asp:TextBox><cc1:XCurriculum ID="XCurriculum" runat="server"
TabIndex="-1"></cc1:XCurriculum>
<ajax:PopupControlExtender ID="popExCurriculum" runat="server" TargetControlID="txtCurriculum"
BehaviorID="exCurriculumClose" PopupControlID="pnlListCurriculum" CommitProperty="value"
Position="Bottom" OffsetY="2" />
<asp:HiddenField ID="HFCurriculumID" runat="server" Value="0" />
</div>
<br />
<div class="editor-label" style="font-weight: bold;">
Faculty :
</div>
<div class="editor-field">
<asp:TextBox ID="txtFaculty" runat="server" CssClass="txt-drop-down" TabIndex="44"
ReadOnly="true" Width="16px"></asp:TextBox><cc1:XFaculty ID="XFaculty" runat="server"
TabIndex="-1"></cc1:XFaculty>
<ajax:PopupControlExtender ID="PopExFaculty" runat="server" TargetControlID="txtFaculty"
BehaviorID="exFacultyClose" PopupControlID="pnlListFaculty" CommitProperty="value"
Position="Bottom" OffsetY="2" />
<asp:HiddenField ID="HFFacultyID" runat="server" Value="0" />
</div>
<br />
<div class="editor-label" style="font-weight: bold;">
<asp:Button ID="btnGet" runat="server" Text="Get Topics"
onclick="btnGet_Click" />
</div>
</div>
</div>
<br />
<br />
<b>Topics : </b>
<br />
<br />
<div style="width: 100%; float: left; height: 250px; overflow: scroll; border: solid 1px gray;">
<asp:Repeater ID="rptTopics" runat="server">
<HeaderTemplate>
<table class="grid-new" cellpadding="0" cellspacing="0" id="table1">
<thead>
<th class="myheadth" style="text-align: left; width: 40px;">
Srno.
</th>
<th class="myheadth" style="text-align: left; width: 300px;">
Topic
</th>
<th class="myheadth" style="text-align: left; width: 80px;">
Topic Date
</th>
<th class="myheadth" style="text-align: left; width: 60px;">
St. Time
</th>
<th class="myheadth" style="text-align: left; width: 60px;">
En. Time
</th>
<th class="myheadth" style="text-align: left;">
Classroom
</th>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="text-align: left; width: 40px;">
<%#Container.ItemIndex+1 %>
</td>
<td style="text-align: left; width: 300px;">
<asp:Label ID="lblID" runat="server" Text='<%#Eval("ID")%>' Visible="false"></asp:Label>
<%#Eval("TopicName")%>
</td>
<td style="text-align: left; width: 80px;">
<div id="DatepickerDiv" class="demo">
<asp:TextBox ID="txtTopicDate" runat="server" CssClass="DatepickerInput" Font-Names="Verdana"
TabIndex="5" Font-Size="11px" Width="70px" Style="border: solid 1px gray;"></asp:TextBox>
</div>
</td>
<td style="text-align: left; width: 60px;">
<cc1:XStartTime ID="XStartTime" runat="server" Width="50px"></cc1:XStartTime>
</td>
<td style="text-align: left; width: 60px;">
<cc1:XEndTime ID="XEndTime" runat="server" Width="50px"></cc1:XEndTime>
</td>
<td style="text-align: left;">
<asp:DropDownList ID="ddlListView" runat="server">
</asp:DropDownList>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody> </table>
</FooterTemplate>
</asp:Repeater>
</div>
<div style="width:100%; float:left; padding-top:20px;">
<asp:Button ID="btnSave" runat="server" Text="Save" Width="70px" OnClick="btnSave_Click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" ID="updPanels">
<ContentTemplate>
<asp:Panel ID="pnlListBranchs" runat="server" BackColor="White" ForeColor="Black"
Width="300px" Height="250px" ScrollBars="Vertical" BorderStyle="Solid" BorderWidth="1px"
BorderColor="Gray">
<PD:PopupSelectAny ID="pdBranchs" runat="server" />
</asp:Panel>
<asp:Panel ID="pnlListCourse" runat="server" BackColor="White" ForeColor="Black"
Width="300px" Height="250px" ScrollBars="Vertical" BorderStyle="Solid" BorderWidth="1px"
BorderColor="Gray">
<PD:PopupSelectAny ID="pdCourse" runat="server" />
</asp:Panel>
<asp:Panel ID="pnlListBatch" runat="server" BackColor="White" ForeColor="Black" Width="300px"
Height="250px" ScrollBars="Vertical" BorderStyle="Solid" BorderWidth="1px" BorderColor="Gray">
<PD:PopupSelectAny ID="pdBatch" runat="server" />
</asp:Panel>
<asp:Panel ID="pnlListCurriculum" runat="server" BackColor="White" ForeColor="Black"
Width="300px" Height="250px" ScrollBars="Vertical" BorderStyle="Solid" BorderWidth="1px"
BorderColor="Gray">
<PD:PopupSelectAny ID="pdCurriculum" runat="server" />
</asp:Panel>
<asp:Panel ID="pnlListFaculty" runat="server" BackColor="White" ForeColor="Black"
Width="300px" Height="250px" ScrollBars="Vertical" BorderStyle="Solid" BorderWidth="1px"
BorderColor="Gray">
<PD:PopupSelectAny ID="pdFaculty" runat="server" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Code Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Scheduling_UC_TopicSchedulingNew : System.Web.UI.UserControl
{
delegate void dlgTsBranchs();
delegate void dlgTsClassrooms();
delegate void dlgTsCourses();
delegate void dlgTsBatches();
delegate void dlgTsCurriculums();
delegate void dlgTsFaculties();
protected void Page_Load(object sender, EventArgs e)
{
this.pdBranchs.dlgSelectRecords += new dlgSelectRecords(pdBranchs_dlgSelectRecords);
dlgTsBranchs dlgTsBranchs = new dlgTsBranchs(getBranchs);
this.pdBranchs.PageMethodWithListRecords = dlgTsBranchs;
this.pdCourse.dlgSelectRecords += new dlgSelectRecords(pdCourse_dlgSelectRecords);
dlgTsCourses dlgTsCourses = new dlgTsCourses(getCourses);
this.pdCourse.PageMethodWithListRecords = dlgTsCourses;
this.pdFaculty.dlgSelectRecords += new dlgSelectRecords(pdFaculty_dlgSelectRecords);
dlgTsFaculties dlgTsFaculties = new dlgTsFaculties(getFaculties);
this.pdFaculty.PageMethodWithListRecords = dlgTsFaculties;
this.pdBatch.dlgSelectRecords += new dlgSelectRecords(pdBatch_dlgSelectRecords);
dlgTsBatches dlgAdBatches = new dlgTsBatches(getBatches);
this.pdBatch.PageMethodWithListRecords = dlgAdBatches;
this.pdCurriculum.dlgSelectRecords += new dlgSelectRecords(pdCurriculum_dlgSelectRecords);
dlgTsCurriculums dlgTsCurriculums = new dlgTsCurriculums(getCurriculum);
this.pdCurriculum.PageMethodWithListRecords = dlgTsCurriculums;
if (!IsPostBack)
{
disbleEnterKeyForTextBoxes();
}
}
public void disbleEnterKeyForTextBoxes()
{
XTime.Attributes.Add("onkeydown", "return (event.keyCode!=13);");
}
void pdFaculty_dlgSelectRecords(object source, RepeaterCommandEventArgs e, string selval)
{
String[] Myvals = selval.Split('\t');
XFaculty.Text = Myvals[0].ToString();
HFFacultyID.Value = Myvals[1].ToString();
PopExFaculty.Cancel();
}
void pdCurriculum_dlgSelectRecords(object source, RepeaterCommandEventArgs e, string selval)
{
String[] Myvals = selval.Split('\t');
XCurriculum.Text = Myvals[0].ToString();
HFCurriculumID.Value = Myvals[1].ToString();
popExCurriculum.Cancel();
getFaculties();
XFaculty.Text = "";
HFFacultyID.Value = "0";
rptTopics.DataSource = null;
rptTopics.DataBind();
}
void pdBatch_dlgSelectRecords(object source, RepeaterCommandEventArgs e, string selval)
{
String[] Myvals = selval.Split('\t');
XBatch.Text = Myvals[0].ToString();
HFBatchID.Value = Myvals[1].ToString();
PopExBatch.Cancel();
Models.Batch objBatch = new BLL.Batch().OpenByID(HFBatchID.Value);
XTime.Text = objBatch.Time;
XStartDate.Text = objBatch.StDate;
XEndDate.Text = objBatch.EnDate;
HFBatchClRoom.Value = objBatch.ClassRoomID.ToString();
getCurriculum();
XCurriculum.Text = "";
HFCurriculumID.Value = "0";
XFaculty.Text = "";
HFFacultyID.Value = "0";
rptTopics.DataSource = null;
rptTopics.DataBind();
}
void pdCourse_dlgSelectRecords(object source, RepeaterCommandEventArgs e, string selval)
{
String[] Myvals = selval.Split('\t');
XCourse.Text = Myvals[0].ToString();
HFCourseID.Value = Myvals[1].ToString();
PopExCourse.Cancel();
XBatch.Text = "";
HFBatchID.Value = "0";
XTime.Text = "";
XStartDate.Text = "";
XEndDate.Text = "";
getBatches();
XCurriculum.Text = "";
HFCurriculumID.Value = "0";
XFaculty.Text = "";
HFFacultyID.Value = "0";
rptTopics.DataSource = null;
rptTopics.DataBind();
}
void pdBranchs_dlgSelectRecords(object source, RepeaterCommandEventArgs e, string selval)
{
String[] Myvals = selval.Split('\t');
XBranch.Text = Myvals[0].ToString();
HFBranchID.Value = Myvals[1].ToString();
PopExBranchs.Cancel();
getCourses();
XCourse.Text = "";
HFCourseID.Value = "0";
XBatch.Text = "";
HFBatchID.Value = "0";
XTime.Text = "";
XStartDate.Text = "";
XEndDate.Text = "";
XCurriculum.Text = "";
HFCurriculumID.Value = "0";
XFaculty.Text = "";
HFFacultyID.Value = "0";
rptTopics.DataSource = null;
rptTopics.DataBind();
}
public void getBranchs()
{
try
{
Type newClass = typeof(PopupListSelect.Branch);
Repeater nlpListview = (Repeater)pdBranchs.FindControl("gvpbList");
object created = Activator.CreateInstance(newClass, Session["User"].ToString(), Session["DesigID"].ToString(), nlpListview);
}
catch
{
}
}
public void getCourses()
{
try
{
Type newClass = typeof(PopupListSelect.Course);
Repeater nlpListview = (Repeater)pdCourse.FindControl("gvpbList");
object created = Activator.CreateInstance(newClass, HFBranchID.Value, nlpListview);
}
catch
{
}
}
public void getBatches()
{
try
{
if (Session["DesigID"].Equals("6") || Session["DesigID"].Equals("7"))
{
Type newClass = typeof(PopupListSelect.Batch);
Repeater nlpListview = (Repeater)pdBatch.FindControl("gvpbList");
object created = Activator.CreateInstance(newClass, HFBranchID.Value, HFCourseID.Value, Session["User"].ToString(), nlpListview);
}
else
{
Type newClass = typeof(PopupListSelect.Batch);
Repeater nlpListview = (Repeater)pdBatch.FindControl("gvpbList");
object created = Activator.CreateInstance(newClass, HFBranchID.Value, HFCourseID.Value, nlpListview);
}
}
catch
{
}
}
public void getCurriculum()
{
try
{
Type newClass = typeof(PopupListSelect.Curriculum);
Repeater nlpListview = (Repeater)pdCurriculum.FindControl("gvpbList");
object created = Activator.CreateInstance(newClass, nlpListview, HFBatchID.Value);
}
catch
{
}
}
public void getFaculties()
{
try
{
Type newClass = typeof(PopupListSelect.Faculties);
Repeater nlpListview = (Repeater)pdFaculty.FindControl("gvpbList");
object created = Activator.CreateInstance(newClass, HFBranchID.Value, HFCurriculumID.Value, HFBatchID.Value, nlpListview);
}
catch
{
}
}
public void getTopics()
{
try
{
Type newClass = typeof(PopupListSelect.Topics);
object created = Activator.CreateInstance(newClass, HFCurriculumID.Value, rptTopics);
String[] TimeVals = XTime.Text.Split('-');
foreach (RepeaterItem itm in rptTopics.Items)
{
TextBox XStartTime = (TextBox)itm.FindControl("XStartTime");
TextBox XEndTime = (TextBox)itm.FindControl("XEndTime");
DropDownList ddlListView = (DropDownList)itm.FindControl("ddlListView");
XStartTime.Text = TimeVals[0].ToString().Trim();
XEndTime.Text = TimeVals[1].ToString().Trim();
try
{
newClass = typeof(PopupListSelect.Classrooms);
created = Activator.CreateInstance(newClass, Int32.Parse(HFBranchID.Value), ddlListView);
ddlListView.SelectedValue = HFBatchClRoom.Value;
}
catch
{
}
}
}
catch
{
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataColumn dc;
DataRow dr;
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.Int32");
dc.ColumnName = "BranchID";
dc.Unique = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.Int32");
dc.ColumnName = "CourseID";
dc.Unique = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.Int32");
dc.ColumnName = "BatchID";
dc.Unique = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.Int32");
dc.ColumnName = "CurriID";
dc.Unique = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.Int32");
dc.ColumnName = "TopicID";
dc.Unique = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.String");
dc.ColumnName = "TopicDate";
dc.Unique = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.String");
dc.ColumnName = "StartTime";
dc.Unique = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.String");
dc.ColumnName = "EndTime";
dc.Unique = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.Int32");
dc.ColumnName = "ClassroomID";
dc.Unique = false;
dt.Columns.Add(dc);
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.String");
dc.ColumnName = "FacultyID";
dc.Unique = false;
dt.Columns.Add(dc);
foreach (RepeaterItem itm in rptTopics.Items)
{
TextBox XStartTime = (TextBox)itm.FindControl("XStartTime");
TextBox XEndTime = (TextBox)itm.FindControl("XEndTime");
DropDownList ddlListView = (DropDownList)itm.FindControl("ddlListView");
TextBox txtTopicDate = (TextBox)itm.FindControl("txtTopicDate");
Label lblID = (Label)itm.FindControl("lblID");
if (!txtTopicDate.Text.Equals(""))
{
dr = dt.NewRow();
dr["BranchID"] = Int32.Parse(HFBranchID.Value);
dr["CourseID"] = Int32.Parse(HFCourseID.Value);
dr["BatchID"] = Int32.Parse(HFBatchID.Value);
dr["CurriID"] = Int32.Parse(HFCurriculumID.Value);
dr["TopicID"] = Int32.Parse(lblID.Text);
dr["TopicDate"] = new Common.GeneralFunctions().ConvertDate_MM_DD_YY(txtTopicDate.Text.Trim());
dr["StartTime"] = XStartTime.Text;
dr["EndTime"] = XEndTime.Text;
dr["ClassroomID"] = Int32.Parse(ddlListView.SelectedValue);
dr["FacultyID"] = HFFacultyID.Value;
dt.Rows.Add(dr);
}
}
TopicScheduling.ScheduledTopics.XMLSaveTopicsToSchedule(dt);
Response.Redirect("~/Topic-Scheduling");
}
protected void btnGet_Click(object sender, EventArgs e)
{
getTopics();
//new BLL.Sch().Topics(Int32.Parse(HFBranchID.Value), Int32.Parse(HFCourseID.Value), Int32.Parse(HFBatchID.Value), Int32.Parse(HFCurriculumID.Value),HFFacultyID.Value,rptTopics);
Models.ScheduledTopics obj = new Models.ScheduledTopics();
obj.BranchID = Int32.Parse(HFBranchID.Value);
obj.CourseID = Int32.Parse(HFCourseID.Value);
obj.BatchID = Int32.Parse(HFBatchID.Value);
obj.CurriID = Int32.Parse(HFCurriculumID.Value);
List<Models.ScheduledTopics> objCollect = TopicScheduling.ScheduledTopics.ScheduledTopicsList(obj);
foreach (RepeaterItem itm in rptTopics.Items)
{
TextBox XStartTime = (TextBox)itm.FindControl("XStartTime");
TextBox XEndTime = (TextBox)itm.FindControl("XEndTime");
DropDownList ddlListView = (DropDownList)itm.FindControl("ddlListView");
TextBox txtTopicDate = (TextBox)itm.FindControl("txtTopicDate");
Label lblID = (Label)itm.FindControl("lblID");
for (int i = 0; i <= objCollect.Count - 1; i++)
{
if (objCollect[i].TopicID.ToString().Equals(lblID.Text))
{
XStartTime.Text = objCollect[i].StartTime;
XEndTime.Text = objCollect[i].EndTime;
txtTopicDate.Text = objCollect[i].TopicDate;
ddlListView.SelectedValue = objCollect[i].ClassroomID.ToString();
if (!HFFacultyID.Value.Equals(objCollect[i].FacultyID))
{
txtTopicDate.Enabled = false;
XStartTime.Enabled = false;
XEndTime.Enabled = false;
ddlListView.Enabled = false;
txtTopicDate.ForeColor = System.Drawing.Color.Red;
}
else
{
txtTopicDate.Enabled = true;
XStartTime.Enabled = true;
XEndTime.Enabled = true;
ddlListView.Enabled = true;
txtTopicDate.ForeColor = System.Drawing.Color.Green;
}
}
}
}
}
}

Yo mut ensure you have trust connection from your web server and your database server. i suggest you to ping database server from your web server,
For dignostic i suggest you also to read event log from your web server

Related

How to transfer this code from ASP.NET to ASP.NET MVC to print crystal reports

I have ASP.NET application and some crystal reports and I need to transfer the following code from ASP.NET and use same functionality in MVC , I am using entity framework.
this is the form.aspx code which i send the parameters value to the other form by using hyperlink and NavigateUrl:
<asp:GridView ID="GridView1" Width="100%" CssClass="dynamicTable table table-striped table-bordered table-condensed" style="color:#000000;background-color:#f4eb3c " AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField>
<HeaderTemplate>Print</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:HyperLink ID="HyperLink1" NavigateUrl='<%#"/RPT/WebForm1.aspx?order_id=" +Eval("order number")+"&DEPT ID=" +Eval("DEPTID")+"&Test Id=" +Eval("Test Id")+"&Culture=" +Eval("Culture")%>' runat="server">Print Result</asp:HyperLink></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Patient MRN#</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LblTest" runat="server" Text='<%# Eval("Patient No") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Order Number</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LblTest" runat="server" Text='<%# Eval("order number") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Patient Name</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LblTest" runat="server" Text='<%# Eval("Patient Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>AGE</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LblTest" runat="server" Text='<%# Eval("AGE") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Request Date</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LblTest" runat="server" Text='<%# Eval("Collection Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Report Date</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LblTest" runat="server" Text='<%# Eval("Report Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Test Name</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LblTest" runat="server" Text='<%# Eval("Test_Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Result</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LblTest" runat="server" Text='<%# Eval("Result") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Ref.Range From</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Reflow" runat="server" Text='<%# Eval("Low Range") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>To</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Reflow" runat="server" Text='<%# Eval("High Range") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Text Range</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Reflow" runat="server" Text='<%# Eval("Text Range") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>REQ. FORM NO.</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="req" runat="server" Text='<%# Eval("REQ FORM NUMBER") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LblTest" Visible="false" runat="server" Text='<%# Eval("DEPTID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LblTest" Visible="false" runat="server" Text='<%# Eval("Culture") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>No Data Found - لم يتم العثور على بيانات</EmptyDataTemplate>
</asp:GridView>
This is the ASP.NET webform.aspx.cs code :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TXTORDERID.Text = Request.QueryString["order_number"].ToString();
TXTDEPTID.Text = Request.QueryString["DEPTID"].ToString();
TXTTESTID.Text = Request.QueryString["Test_Id"].ToString();
TXTCULTURE.Text = Request.QueryString["Culture"].ToString();
ReportDocument reportDocument = new ReportDocument();
ParameterFields paramFields = new ParameterFields();
ParameterField paramField = new ParameterField();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();
ParameterField parameterField1 = new ParameterField();
ParameterDiscreteValue parameterDiscreteValue1 = new ParameterDiscreteValue();
ParameterFields parameterFields = new ParameterFields();
if (Convert.ToInt32(TXTDEPTID.Text) == 7 && Convert.ToInt32(TXTCULTURE.Text) == 1)
{
TXTPOSITIVE.Text = Request.QueryString["Positive"].ToString();
}
if (Session["UserCustid"] != null && Convert.ToInt32(Session["UserCustid"]) > 0)
{
if (Convert.ToInt32(TXTDEPTID.Text) == 1 || Convert.ToInt32(TXTDEPTID.Text) == 2 || Convert.ToInt32(TXTDEPTID.Text) == 3 || Convert.ToInt32(TXTDEPTID.Text) == 4)
{
paramField.Name = "#ORDER_ID";
paramDiscreteValue.Value = TXTORDERID.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField = new ParameterField(); // <-- This line is added
paramDiscreteValue = new ParameterDiscreteValue(); // <-- This line is added
paramField.Name = "#deptid";
paramDiscreteValue1.Value = TXTDEPTID.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue1);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
reportDocument.Load(Server.MapPath("~/RPT/RPT_RESULTS.rpt"));
CrystalReportViewer1.ReportSource = reportDocument;
reportDocument.SetDatabaseLogon("DBadmin", "1111");
var connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "DB";
connectionInfo.DatabaseName = "DB";
connectionInfo.Password = "1111";
connectionInfo.UserID = "DBadmin";
connectionInfo.Type = ConnectionInfoType.SQL;
connectionInfo.IntegratedSecurity = false;
for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++)
{
CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;
}
}
else if (Convert.ToInt32(TXTDEPTID.Text) == 5)
{
paramField.Name = "#Criteria";
paramDiscreteValue.Value = TXTORDERID.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField = new ParameterField(); // <-- This line is added
paramDiscreteValue = new ParameterDiscreteValue(); // <-- This line is added
paramField.Name = "#TESTID";
paramDiscreteValue1.Value = TXTDEPTID.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue1);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
reportDocument.Load(Server.MapPath("~/RPT/RPT_HISTO_RESULT.rpt"));
CrystalReportViewer1.ReportSource = reportDocument;
reportDocument.SetDatabaseLogon("DBadmin", "1111");
var connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "DB";
connectionInfo.DatabaseName = "DB";
connectionInfo.Password = "1111";
connectionInfo.UserID = "DBadmin";
connectionInfo.Type = ConnectionInfoType.SQL;
connectionInfo.IntegratedSecurity = false;
for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++)
{
CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;
}
}
else if (Convert.ToInt32(TXTDEPTID.Text) == 6 && Convert.ToInt32(TXTTESTID.Text) == 1106)
{
paramField.Name = "#Criteria";
paramDiscreteValue.Value = TXTORDERID.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
reportDocument.Load(Server.MapPath("~/RPT/RPT_SEMEN_RESULT.rpt"));
CrystalReportViewer1.ReportSource = reportDocument;
reportDocument.SetDatabaseLogon("DBadmin", "1111");
var connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "DB";
connectionInfo.DatabaseName = "DB";
connectionInfo.Password = "1111";
connectionInfo.UserID = "DBadmin";
connectionInfo.Type = ConnectionInfoType.SQL;
connectionInfo.IntegratedSecurity = false;
for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++)
{
CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;
}
}
IN ASP.NET MVC :
1- I created a webform.aspx.cs and used same code above in MVC project
2- I created the controller code and view
this is the view code :
<div id="hemadiv">
#if (labhema1 != null && labhema1.Report_Date.HasValue)
{
<img width="700" height="200" src="~/Contents/images/aljawdahlogo.png" />
Print Result
<table class="table table-bordered">
<tr>
<td style="text-align:center">
<input type="submit" value="Heamatology Result " onclick="PrintElemhema('#hemadiv')" class="btn btn-primary" />
</td>
</tr>
</table>
<div>
<dl class="horizontal" style="padding:10px">
<dt style="width: 20%;display: inline-block;color:blue;">#Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Patient_Name)</dt>
<dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">#Html.DisplayFor(model => model.labCashView.FirstOrDefault().Patient_Name)</dd>
<dt style="width: 22%;display: inline-block;color:blue;">#Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Customer_Name)</dt>
<dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">#Html.DisplayFor(model => model.labCashView.FirstOrDefault().Customer_Name)</dd>
<dt style="width: 20%;display: inline-block;color:blue;">#Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Patient_No)</dt>
<dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">#Html.DisplayFor(model => model.labCashView.FirstOrDefault().Patient_No)</dd>
<dt style="width: 22%;display: inline-block;margin-left:0px;color:blue;">#Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Collection_Date)</dt>
<dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">#Html.DisplayFor(model => model.labCashView.FirstOrDefault().Collection_Date)</dd>
<dt style="width: 20%;display: inline-block;color:blue;">#Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().SEX)</dt>
<dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">#Html.DisplayFor(model => model.labCashView.FirstOrDefault().SEX)</dd>
<dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">#Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Receiving_Date)</dt>
<dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">#Html.DisplayFor(model => model.labCashView.FirstOrDefault().Receiving_Date)</dd>
<dt style="width: 20%;display: inline-block;color:blue;">#Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().AGE)</dt>
<dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">#Html.DisplayFor(model => model.labCashView.FirstOrDefault().AGE)</dd>
<dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">#Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Report_Date)</dt>
<dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">#Html.DisplayFor(model => model.labCashView.FirstOrDefault().Report_Date)</dd>
<dt style="width: 20%;display: inline-block;color:blue;">#Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().order_number)</dt>
<dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">#Html.DisplayFor(model => model.labCashView.FirstOrDefault().order_number)</dd>
</dl>
</div>
<div class="tab-pane container active" id="hemadiv">
#*<h5 class="text-uppercase p-2 text-center">Hematology Department</h5>*#
<table class="table table-bordered" cellpadding="5" cellspacing="5" >
<thead>
<tr>
#*<th>#Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Patient_No)</th>
<th>#Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Patient_Name)</th>*#
<th>#Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Test_Name)</th>
<th>#Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Result)</th>
<th>#Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Low_Range)</th>
<th>#Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().High_Range)</th>
<th>#Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Text_Range)</th>
#*<th>#Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Report_Date)</th>*#
</tr>
</thead>
#foreach (var employee in Model.labCashView.Where(x => hema.Contains(x.DEPTID.GetValueOrDefault())))
{
<tr>
#*<td>#employee.Patient_No</td>
<td>#employee.Patient_Name</td>*#
<td>#employee.Test_Name</td>
<td>#employee.Result</td>
<td>#employee.Low_Range</td>
<td>#employee.High_Range</td>
<td>#employee.Text_Range</td>
#*<td>#employee.Report_Date</td>*#
</tr>
}
</table>
</div>
}
3- this is the controller code :
public ActionResult CashData(int id)
{
var tables = new Orders_Tables
{
testsRanges = db.TestsRanges.ToList(),
LabResults = db.LAB_RESULTS.Where(o => o.ORDER_ID == id)
.Include(p => p.LabTests)
.Include(t => t.Patients).ToList(),
LabParaResult = db.LAB_PARA_RESULTS.Where(o => o.ORDER_ID == id).Include(t => t.Patients).Include(t => t.LabTests).Include(c => c.Customers).ToList(),
LabCultureResults = db.LAB_CULTURE_RESULT.Where(o => o.ORDER_ID == id).Include(t => t.Patients).Include(t => t.LabTests).Include(c => c.Customers).ToList(),
LabMicroResults = db.LAB_MICRO_NEGATIVE_RESULT.Where(o => o.ORDER_ID == id).ToList(),
labCashView = db.LAB_RESULT_CASH_VIEW.Where(o => o.order_number == id).ToList(),
LabParasitologyView = db.LAB_PARASITOLOGY_VIEW.Where(o => o.order_number == id).ToList(),
LabCulturesView = db.LAB_CULTURES_VIEW.Where(o => o.ORDER_ID == id).ToList(),
LabMicroView = db.LAB_MICRO_VIEW.Where(o => o.ORDER_ID == id).ToList(),
LabHistopathologyView = db.LAB_HISTOPATHOLOGY_VIEW.Where(o => o.ORDER_ID == id).ToList(),
LabHistoResult = db.LAB_HISTO_RESULT.Where(o => o.ORDER_ID == id).ToList(),
labtests = db.LabTests.ToList(),
// patients = db.Patients.ToList()
};
4- i created the class LABCASHVIEW
I checked alot of articles in stackoverflow site and one answer just he wrote you can use same design from ASP.NET in ASP.NET MVC
create webform in your MVC project and pass the parameters from MVC to webform then it will work and print crystal reports as same as ASP.NET .
So I did what he said but now I need the final step , How to pass the following parameters from MVC view to webform and print crystal reports :
I need to send the selected order_number , dept_Id , Test_Id and culture parameters from selected row to webform and print crystal report
I used
<a> tag and href="" to
but how to pass all this parameter one time to webform and avoid the error reference object not set to an instance of an object and check if parameters not null first ?
this is the question and answer but no details how to call crystal reports and how to pass multiple parameters to crystal report , for example if i need to print selected order_id or selected invoice :
https://stackoverflow.com/questions/348785/crystal-reports-in-asp-net-mvc
UPDATE :
I gave static values for these textboxes in webform.aspx.cs
and its printing now :
TXTORDERID.Text = "2000000054";
TXTDEPTID.Text = "1";
TXTTESTID.Text = "46";
TXTCULTURE.Text = "2";
now final issue how to send the value for these text boxes in webform from MVC view as the following :
TXTORDERID.Text = Request.QueryString["labCashView.order_number"].ToString();
TXTDEPTID.Text = Request.QueryString["labCashView.DEPTID"].ToString();
TXTTESTID.Text = Request.QueryString["labCashView.Test_Id"].ToString();
TXTCULTURE.Text = Request.QueryString["labCashView.Culture"].ToString();
As I see you completed everything and you need to pass parameters from View to crystal reports try this solution :
Print Result
Then in webform.aspx.cs write the following code and use the value passed from the link :
TXTORDERID.Text = Request.QueryString["order_number"].ToString();
TXTDEPTID.Text = Request.QueryString["deptid"].ToString();
TXTTESTID.Text = Request.QueryString["testid"].ToString();
TXTCULTURE.Text = Request.QueryString["Culture"].ToString();
Hope this will help you and print crystal reports in your MVC view.

How to fix code have select all asp:CheckBoxList within current table only in .NET C# same as "JQuery - Select All CheckBoxes within..." question?

How to fix code have select all asp:CheckBoxList within current table only in .NET C# same as "JQuery - Select All CheckBoxes within current table only" question ?
Because I try coding with sample but can't select all asp:CheckBoxList within current table only.
Link to "JQuery - Select All CheckBoxes within current table only" question.
My snipplet to describe problem.
<!DOCTYPE html>
<html>
<head>
<script
type="text/javascript"
src="//code.jquery.com/jquery-1.6.4.js"></script>
<style>
form , p , td, th{
font-size: 24px;
}
input.largerCheckbox
{
width: 22px;
height: 22px;
}
</style>
</head>
<body>
<h1>Show checkboxes:</h1>
<p><label><input type="checkbox" class="largerCheckbox" id="checkAll"/> Check all</label></p>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"><br><br>
<table id="myTable">
<tr class="header">
<th>Checkbox</th>
<th>Number</th>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle1" value="1"></td>
<td>1</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle2" value="11"></td>
<td>11</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle3" value="111"></td>
<td>111</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle4" value="1111"></td>
<td>1111</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle5" value="11111"></td>
<td>11111</td>
</tr>
</table>
<script>
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
<script>
$("#checkAll").change(function () {
$("input:checkbox").prop('checked', $(this).prop("checked"));
});
</script>
</body>
</html>
My full source code.
https://github.com/doanga2007/CheckLoopQR3
Sample code at the bottom.
Default.aspx (HTML Code)
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CheckLoopQR3.Default" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-1.6.4.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<style>
#myInput {
font-size: 16px;
padding: 6px 20px 6px 10px;
border: 1px solid #ddd;
margin-bottom: 3px;
}
</style>
<script type="text/javascript">
$(window).load(function(){
$("#checkAll").change(function () {
$("input:checkbox").prop('checked', $(this).prop("checked"));
});
});
</script>
<script>
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("CheckBox1");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<h2>QR Code Generator</h2>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Please Input Data</label>
<div class="input-group">
<asp:TextBox ID="txtQRCode" runat="server" CssClass="form-control"></asp:TextBox>
<div class="input-group-prepend">
<asp:Button ID="btnGenerate" runat="server" CssClass="btn btn-secondary" Text="Generate" OnClick="btnGenerate_Click" />
</div>
</div>
</div>
</div>
</div>
<asp:Button ID="btnSelect" runat="server" CssClass="btn btn-secondary" Text="Display Text" OnClick="btnSelect_Click" /><br /><br />
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:CheckBox ID="checkAll" runat="server" Font-Size="Large"/><asp:Label id="checkTextAll" runat="server" Font-Size="Large"></asp:Label><br /><br />
<label>Input Number to Search </label>
<input type="text" id="myInput" onkeyup="myFunction()"><br /><br />
<asp:CheckBoxList ID="CheckBox1" runat="server" Border="1"
BorderColor="LightGray" Font-Size="Large"></asp:CheckBoxList>
</div>
</form>
</body>
</html>
Default.aspx.cs (C# Code)
using System;
using System.Drawing;
using System.IO;
using ZXing;
using ZXing.QrCode;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CheckLoopQR3
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.checkTextAll.Text = " Check All";
}
protected void btnSelect_Click(object sender, EventArgs e)
{
string code = txtQRCode.Text;
long num = Convert.ToInt64(code);
int i;
for (i = 1; i < 6; i++)
{
num *= i;
CheckBox1.Items.Add(new ListItem(" " + num));
}
}
protected void btnGenerate_Click(object sender, EventArgs e)
{
if (CheckBox1.SelectedItem == null)
{
Response.Redirect("Default.aspx");
}
string[] texture = { "Selected Text 1 -> ", "Selected Text 2 -> ", "Selected Text 3 -> ",
"Selected Text 4 -> ", "Selected Text 5 -> "};
string[] texture2 = { " is Checkbox 1.", " is Checkbox 2.", " is Checkbox 3.",
" is Checkbox 4.", " is Checkbox 5."};
foreach (ListItem listItem in CheckBox1.Items)
{
if (listItem.Selected)
{
int a = CheckBox1.Items.IndexOf(listItem);
a = a + 1;
string code = listItem.Text;
CheckBox1.Visible = false;
checkAll.Visible = false;
checkTextAll.Visible = false;
QrCodeEncodingOptions options = new QrCodeEncodingOptions();
options = new QrCodeEncodingOptions
{
DisableECI = true,
CharacterSet = "UTF-8",
Width = 150,
Height = 150,
Margin = 0,
};
var barcodeWriter = new BarcodeWriter();
barcodeWriter.Format = BarcodeFormat.QR_CODE;
barcodeWriter.Options = options;
System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
imgBarCode.Height = 150;
imgBarCode.Width = 150;
Label lblvalues = new Label();
lblvalues.Text += texture[a - 1] + listItem.Text + texture2[a - 1];
lblvalues.Font.Size = FontUnit.Large;
using (Bitmap bitMap = barcodeWriter.Write(code))
{
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
}
PlaceHolder1.Controls.Add(imgBarCode);
PlaceHolder1.Controls.Add(new HtmlGenericControl("br"));
PlaceHolder1.Controls.Add(lblvalues);
PlaceHolder1.Controls.Add(new HtmlGenericControl("br"));
}
}
else
{
//do something else
}
}
}
}
}
Good news : I have answer to fix code have select all asp:CheckBoxList within current table only in .NET C# same as "JQuery - Select All CheckBoxes within current table only" question.
Key of answer to "jQuery :visible Selector".
jQuery :
$(window).load(function(){
$("#checkAll").change(function () {
$("input:checkbox:visible").prop('checked', $(this).prop("checked"));
});
});
My snipplet to another solve problem in HTML.
<!DOCTYPE html>
<html>
<head>
<script
type="text/javascript"
src="//code.jquery.com/jquery-1.6.4.js"></script>
<style>
form , p , td, th{
font-size: 24px;
}
input.largerCheckbox
{
width: 22px;
height: 22px;
}
</style>
</head>
<body>
<h1>Show checkboxes:</h1>
<p><label><input type="checkbox" class="largerCheckbox" id="checkAll"/> Check all</label></p>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"><br><br>
<table id="myTable">
<tr class="header">
<th>Checkbox</th>
<th>Number</th>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle1" value="1"></td>
<td>1</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle2" value="11"></td>
<td>11</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle3" value="111"></td>
<td>111</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle4" value="1111"></td>
<td>1111</td>
</tr>
<tr>
<td><input type="checkbox" class="largerCheckbox" name="vehicle5" value="11111"></td>
<td>11111</td>
</tr>
</table>
<script>
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
<script>
$("#checkAll").change(function () {
$("input:checkbox:visible").prop('checked', $(this).prop("checked"));
});
</script>
</body>
</html>
My full source code.
https://github.com/doanga2007/CheckLoopQR3
Default.aspx (HTML Code)
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CheckLoopQR3.Default" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-1.6.4.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<style>
#myInput {
font-size: 16px;
padding: 6px 20px 6px 10px;
border: 1px solid #ddd;
margin-bottom: 3px;
}
</style>
<script type="text/javascript">
$(window).load(function(){
$("#checkAll").change(function () {
$("input:checkbox:visible").prop('checked', $(this).prop("checked"));
});
});
</script>
<script>
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("CheckBox1");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<h2>QR Code Generator</h2>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Please Input Data</label>
<div class="input-group">
<asp:TextBox ID="txtQRCode" runat="server" CssClass="form-control"></asp:TextBox>
<div class="input-group-prepend">
<asp:Button ID="btnGenerate" runat="server" CssClass="btn btn-secondary" Text="Generate" OnClick="btnGenerate_Click" />
</div>
</div>
</div>
</div>
</div>
<label>Input Number to Search </label>
<input type="text" id="myInput" onkeyup="myFunction()"><br />
<asp:Button ID="btnSelect" runat="server" CssClass="btn btn-secondary" Text="Display Text" OnClick="btnSelect_Click" /><br /><br />
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:CheckBox ID="checkAll" runat="server" Font-Size="Large"/><asp:Label id="checkTextAll" runat="server" Font-Size="Large"></asp:Label><br /><br />
<asp:CheckBoxList ID="CheckBox1" runat="server" Border="1"
BorderColor="LightGray" Font-Size="Large"></asp:CheckBoxList>
</div>
</form>
</body>
</html>
Default.aspx.cs (C# Code)
using System;
using System.Drawing;
using System.IO;
using ZXing;
using ZXing.QrCode;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CheckLoopQR3
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.checkTextAll.Text = " Check All";
}
protected void btnSelect_Click(object sender, EventArgs e)
{
string code = txtQRCode.Text;
long num = Convert.ToInt64(code);
int i;
for (i = 1; i < 6; i++)
{
num *= i;
CheckBox1.Items.Add(new ListItem(" " + num));
}
}
protected void btnGenerate_Click(object sender, EventArgs e)
{
if (CheckBox1.SelectedItem == null)
{
Response.Redirect("Default.aspx");
}
string[] texture = { "Selected Text 1 -> ", "Selected Text 2 -> ", "Selected Text 3 -> ",
"Selected Text 4 -> ", "Selected Text 5 -> "};
string[] texture2 = { " is Checkbox 1.", " is Checkbox 2.", " is Checkbox 3.",
" is Checkbox 4.", " is Checkbox 5."};
foreach (ListItem listItem in CheckBox1.Items)
{
if (listItem.Selected)
{
int a = CheckBox1.Items.IndexOf(listItem);
a = a + 1;
string code = listItem.Text;
CheckBox1.Visible = false;
checkAll.Visible = false;
checkTextAll.Visible = false;
QrCodeEncodingOptions options = new QrCodeEncodingOptions();
options = new QrCodeEncodingOptions
{
DisableECI = true,
CharacterSet = "UTF-8",
Width = 150,
Height = 150,
Margin = 0,
};
var barcodeWriter = new BarcodeWriter();
barcodeWriter.Format = BarcodeFormat.QR_CODE;
barcodeWriter.Options = options;
System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
imgBarCode.Height = 150;
imgBarCode.Width = 150;
Label lblvalues = new Label();
lblvalues.Text += texture[a - 1] + listItem.Text + texture2[a - 1];
lblvalues.Font.Size = FontUnit.Large;
using (Bitmap bitMap = barcodeWriter.Write(code))
{
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
}
PlaceHolder1.Controls.Add(imgBarCode);
PlaceHolder1.Controls.Add(new HtmlGenericControl("br"));
PlaceHolder1.Controls.Add(lblvalues);
PlaceHolder1.Controls.Add(new HtmlGenericControl("br"));
}
}
else
{
//do something else
}
}
}
}
}

ASP button not posting back after exporting a pdf from ashx using response.write

I am exporting a pdf from a json string from database. My export buttons are in a gridview control - Image buttons. I am using a Handler (ashx) file for exporting.
The problem is, after exporting the buttons on the page (one button and one command field) are not posting back. My handler code and aspx code are below
Handler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.IO;
using System.Web.UI;
using System.Data;
using GE.MSA.DataQuality.DataAccess;
using GE.MSA.DataQuality.DataAccess.Authentication;
using GE.MSA.DataQuality.DataAccess.EntityModel;
using Newtonsoft.Json;
namespace GE.MSA.DataQuality.Web
{
/// <summary>
/// Summary description for CreatePDF
/// </summary>
public class CreatePDF : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
int _id = Convert.ToInt32(context.Request.QueryString["Id"]);
string _report = context.Request.QueryString["Report"];
string _lockedfrom = context.Request.QueryString["LockedFrom"];
string _lockedto = context.Request.QueryString["LockedTo"];
string _docheader = (_report == "CostServiceReport" ? "Cost & Service Report - " : "Service Report - ") + "Locked from : " + _lockedfrom + " to " + _lockedto;
string _doctitle = _report + "-" + _lockedfrom + "-" + _lockedto + ".pdf";
DataTable _PDFReport = new DataTable();
if (_report == "CostServiceReport")
{
using (var db = new dbReferenceTablesEntities())
{
string csr = (from i in db.CS_Billing_LockPeriod
where i.ID == _id
select i.CostServiceReport).FirstOrDefault().ToString();
_PDFReport = (DataTable)JsonConvert.DeserializeObject(csr, _PDFReport.GetType());
}
}
else
{
if (_report == "ServiceReport")
{
using (var db = new dbReferenceTablesEntities())
{
string sr = (from i in db.CS_Billing_LockPeriod
where i.ID == _id
select i.ServiceReport).FirstOrDefault().ToString();
_PDFReport = (DataTable)JsonConvert.DeserializeObject(sr, _PDFReport.GetType());
}
}
}
Document pdfDoc = new Document(PageSize.A3, 20, 20, 20, 20);
pdfDoc.SetPageSize(iTextSharp.text.PageSize.A3.Rotate());
try
{
PdfWriter.GetInstance(pdfDoc, System.Web.HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
Chunk c = new Chunk("" + _docheader + "", FontFactory.GetFont("Verdana", 15));
Paragraph p = new Paragraph();
p.Alignment = Element.ALIGN_CENTER;
p.Add(c);
pdfDoc.Add(p);
string clientLogo = context.Server.MapPath(".") + "/images/abc.png";
string imageFilePath = context.Server.MapPath(".") + "/images/abc.png";
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath);
//Resize image depend upon your need
jpg.ScaleToFit(60f, 40f);
//Give space before image
jpg.SpacingBefore = 0f;
//Give some space after the image
jpg.SpacingAfter = 1f;
jpg.Alignment = Element.HEADER;
pdfDoc.Add(jpg);
Font font8 = FontFactory.GetFont("ARIAL", 7);
DataTable dt = _PDFReport;
if (dt != null & dt.Rows.Count > 0)
{
//Craete instance of the pdf table and set the number of column in that table
PdfPTable PdfTable = new PdfPTable(dt.Columns.Count);
PdfTable.HeaderRows = 1;
PdfPCell PdfPCell = null;
for (int i = 0; i < dt.Columns.Count; i++)
{
PdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Columns[i].ColumnName.ToString(), FontFactory.GetFont("Verdana", 12))));
PdfPCell.HorizontalAlignment = Element.ALIGN_CENTER;
PdfPCell.VerticalAlignment = Element.ALIGN_MIDDLE;
PdfPCell.BackgroundColor = new Color(109, 159, 213);
PdfTable.AddCell(PdfPCell);
}
for (int rows = 0; rows < dt.Rows.Count; rows++)
{
for (int column = 0; column < dt.Columns.Count; column++)
{
PdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows][column].ToString(), font8)));
PdfTable.AddCell(PdfPCell);
}
}
//PdfTable.SpacingBefore = 15f; // Give some space after the text or it may overlap the table
pdfDoc.Add(PdfTable); // add pdf table to the document
}
pdfDoc.Close();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("content-disposition", "attachment; filename= " + _doctitle);
System.Web.HttpContext.Current.Response.Write(pdfDoc);
context.Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch (DocumentException de)
{
System.Web.HttpContext.Current.Response.Write(de.Message);
}
catch (IOException ioEx)
{
System.Web.HttpContext.Current.Response.Write(ioEx.Message);
}
catch (Exception ex)
{
System.Web.HttpContext.Current.Response.Write(ex.Message);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
ASPX Page
<%# Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="LockForcing.aspx.cs" Inherits="GE.MSA.DataQuality.Web.LockForcing" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ScriptManager ID="scriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<h2>Lock Force Calculation</h2>
<div>
<fieldset>
<legend>Set Lock Period</legend>
<table>
<tr>
<td>
<label>Start Month</label></td>
<td>
<asp:DropDownList ID="ddlStartMonth" runat="server" Width="100%">
<asp:ListItem>01</asp:ListItem>
<asp:ListItem>02</asp:ListItem>
<asp:ListItem>03</asp:ListItem>
<asp:ListItem>04</asp:ListItem>
<asp:ListItem>05</asp:ListItem>
<asp:ListItem>06</asp:ListItem>
<asp:ListItem>07</asp:ListItem>
<asp:ListItem>08</asp:ListItem>
<asp:ListItem>09</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
</asp:DropDownList></li></td>
<td></td>
<td>
<label>Start Year</label></td>
<td>
<asp:DropDownList ID="ddlStartYear" runat="server" Width="100%">
</asp:DropDownList></td>
</tr>
<tr>
<td>
<label>End Month</label></td>
<td>
<asp:DropDownList ID="ddlEndMonth" runat="server" Width="100%">
<asp:ListItem>01</asp:ListItem>
<asp:ListItem>02</asp:ListItem>
<asp:ListItem>03</asp:ListItem>
<asp:ListItem>04</asp:ListItem>
<asp:ListItem>05</asp:ListItem>
<asp:ListItem>06</asp:ListItem>
<asp:ListItem>07</asp:ListItem>
<asp:ListItem>08</asp:ListItem>
<asp:ListItem>09</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
</asp:DropDownList></td>
<td></td>
<td>
<label>End Year</label></td>
<td>
<asp:DropDownList ID="ddlEndYear" runat="server" Width="100%">
</asp:DropDownList></td>
<td>
<asp:Button ID="btnLock" runat="server" Width="120px" Text="Lock" CssClass="submitButton"
BorderStyle="None" OnClick="btnLock_Click" />
</td>
<td>
<asp:Label runat="server" ID="lblLockMessage"></asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="5000" Enabled="false" OnTick="Timer1_Tick"></asp:Timer>
</td>
</tr>
</table>
</fieldset>
</div>
<div>
<table width="100%">
<tr>
<td>
<label>Lock Period Details</label>
</td>
<td align="right">
<asp:Label runat="server" ID="lblmsg"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="gvLockPeriod" runat="server" AutoGenerateColumns="false" CssClass="mGrid" OnRowDeleting="gvLockPeriod_RowDeleting"
DataKeyNames="Id">
<Columns>
<asp:CommandField ShowDeleteButton="true" ControlStyle-ForeColor="darkcyan" DeleteText="Unlock"></asp:CommandField>
<asp:BoundField DataField="FromDate" HeaderText="FromDate" />
<asp:BoundField DataField="ToDate" HeaderText="ToDate" />
<asp:TemplateField HeaderText="Cost&ServiceReport">
<ItemTemplate>
<asp:ImageButton ImageUrl="~/images/Pdf-16.png" runat="server" ToolTip="Download Cost & Service Report"
Visible='<%# Convert.ToBoolean(Eval("CostServiceReport")) %>'
PostBackUrl='<%#"CreatePDF.ashx?id="+Eval("Id")+"&Report=CostServiceReport"+"&LockedFrom="+Eval("fromdate")+"&LockedTo="+Eval("todate")+""%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ServiceReport">
<ItemTemplate>
<asp:ImageButton ImageUrl="~/images/Pdf-16.png" runat="server" ToolTip="Download Service Report"
Visible='<%# Convert.ToBoolean(Eval("ServiceReport")) %>'
PostBackUrl='<%#"CreatePDF.ashx?id="+Eval("Id")+"&Report=ServiceReport"+"&LockedFrom="+Eval("fromdate")+"&LockedTo="+Eval("todate")+""%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ModifiedBy" HeaderText="CreatedUser" />
<asp:BoundField DataField="ModifiedDate" HeaderText="CreatedDate" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<div class="overlays" />
<div style="font-weight: bold; align-content: center" class="overlayContents">
<asp:Image ID="aspImg1" runat="server" ImageUrl="~/images/ajax-loader.GIF" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</asp:Content>
After flushing the response call the response end method.
context.Response.Flush();
System.Web.HttpContext.Current.Response.End();

how to bind gridview using Json by onclick event of Linkbutton inside other Gridview?

I am binding Gridview using json (first Gridview),which have some column with linkbutton.
I want to bind other gridview(second Gridview) using json on click of Linkbutton inside first gridview . how can i do this? ,please suggest me how to fire json on linkbutton click event ?
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class StudentWebService : System.Web.Services.WebService {
public StudentWebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public DataTable GetStudents()
{
string constr = #"Server=WAQAS\SQLEXPRESS; Database=SampleDB; uid=sa; pwd=123";
string query = "SELECT ID, Name, Fee FROM Students";
SqlDataAdapter da = new SqlDataAdapter(query, constr);
DataTable table = new DataTable();
da.Fill(table);
return table;
}
[WebMethod]
public int UpdateStudent(int id, string name, decimal fee)
{
SqlConnection con = null;
string constr = #"Server=WAQAS\SQLEXPRESS; Database=SampleDB; uid=sa; pwd=123";
string query = "UPDATE Students SET Name = #Name, Fee = #Fee WHERE ID = #ID";
con = new SqlConnection(constr);
SqlCommand command = new SqlCommand(query, con);
command.Parameters.Add("#Name", SqlDbType.NVarChar).Value = name;
command.Parameters.Add("#Fee", SqlDbType.Decimal).Value = fee;
command.Parameters.Add("#ID", SqlDbType.Int).Value = id;
int result = -1;
try
{
con.Open();
result = command.ExecuteNonQuery();
}
catch (Exception)
{ }
finally
{
con.Close();
}
return result;
}
}
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
StudentWebService service = new StudentWebService();
ListView1.DataSource = service.GetStudents();
ListView1.DataBind();
}
}
}
<!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></title>
<script src="scripts/jquery-1.4.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
var row;
var id, name, fee;
function EditStudent(editButton) {
row = $(editButton).parent().parent();
id = $("#id", row).text();
name = $("#name", row).text();
fee = $("#fee", row).text();
row.addClass("highlightRow");
DisplayEditStudentDialog();
return false;
}
function DisplayEditStudentDialog() {
$("#spnID").text(id);
$("#txtName").val(name);
$("#txtFee").val(fee);
$("#editForm").show();
}
function UpdateStudent(e) {
name = $("#txtName").val();
fee = $("#txtFee").val();
$.ajax({
type: "POST",
url: "StudentWebService.asmx/UpdateStudent",
data: "{'id':'" + id + "', 'name':'" + name + "', 'fee':'" + fee + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
var result = response.d;
if (result > 0) {
$("#name", row).text(name);
$("#fee", row).text(fee);
row.removeClass("highlightRow");
CloseEditStudentDialog();
}
else {
alert('There is some error during update');
}
},
failure: function(msg) {
alert(msg);
}
});
return false;
}
function CloseEditStudentDialog() {
$("#editForm").hide();
row.removeClass("highlightRow");
}
</script>
<style type="text/css">
.table
{
border: solid 2px #507CD1;
width: 50%;
}
th
{
text-align: left;
}
.headerRow
{
background-color: #507CD1;
color: White;
}
.highlightRow
{
background-color: #dadada;
}
.editForm
{
display: none;
position: fixed;
width: 380px;
height: 200px;
top: 50%;
left: 50%;
margin-left: -190px;
margin-top: -100px;
background-color: #ffffff;
border: 2px solid #507CD1;
padding: 0px;
z-index: 102;
font-family: Verdana;
font-size: 10pt;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<table class="table" cellspacing="0" cellpadding="3"
rules="rows">
<tr class="headerRow">
<th style="width:40px;">
</th>
<th style="width:40px;">
ID
</th>
<th style="width:230px;">
Name
</th>
<th style="width:230px;">
Fee
</th>
</tr>
<tbody>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<img id="btnEdit" style="cursor: pointer;" alt="Edit" src="images/edit.png" onclick="EditStudent(this);" />
</td>
<td>
<span id="id"><%# Eval("ID") %></span>
</td>
<td>
<span id="name">
<%# Eval("Name")%></span>
</td>
<td>
<span id="fee">
<%# Eval("Fee")%></span>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<div id="editForm" class="editForm">
<table style="width:100%;" cellpadding="5" cellspacing="0">
<tr class="headerRow">
<td>
Edit Item
</td>
<td style="text-align: right;">
<a onclick="CloseEditStudentDialog();" style="cursor: pointer;">Close</a>
</td>
</tr>
<tr>
<td>
ID:
</td>
<td>
<span id="spnID"></span>
</td>
</tr>
<tr>
<td>
Name:
</td>
<td>
<input type="text" id="txtName" />
</td>
</tr>
<tr>
<td>
Fee:
</td>
<td>
<input type="text" id="txtFee" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" id="btnUpdate" value="Update" onclick="UpdateStudent(); return false;" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

iTextSharp output to PDF

I've been trying to get this working for a long time now and I was hoping that someone could help me out with this. I am trying to save two ListViews from my ASCX control (incorporated to my ASPX page as follows) to a PDF file. I believe that the problem lies in these two lines of code, as I am getting an 'the document has no pages' error when saving. Any ideas would be greatly appreciated! Thanks in advance...
ListView lv1 = (ListView)TagCloudControl1.FindControl("ListView1");
ListView lv2 = (ListView)TagCloudControl1.FindControl("ListView2");
ASPX page:
<%# Register Src="~/tagcloud.ascx" TagName="TagCloudControl" TagPrefix="TagCloud" %>
...
<TagCloud:TagCloudControl ID="TagCloudControl1" runat="server" />
C#:
private void GeneratePDF(string path, string fileName, bool download, string text) {
var document = new Document();
try{
if (download) {
PdfWriter.GetInstance(document, Response.OutputStream);
} else {
PdfWriter.GetInstance(document, new FileStream(path + fileName, FileMode.Create));
}
StringBuilder strB = new StringBuilder();
document.Open();
if (text.Length.Equals(0)) {
TagCloudControl1.BindTagCloud();
using (StringWriter sWriter = new StringWriter(strB)) {
using (HtmlTextWriter htWriter = new HtmlTextWriter(sWriter)) {
//var lv1 = (TagCloudControl)ListView.FindControl("ListView1");
//var lv2 = (TagCloudControl)ListView.FindControl("ListView2");
ListView lv1 = (ListView)TagCloudControl1.FindControl("ListView1");
ListView lv2 = (ListView)TagCloudControl1.FindControl("ListView2");
lv1.RenderControl(htWriter);
lv2.RenderControl(htWriter);
}
}
} else {
strB.Append(text);
}
using (TextReader sReader = new StringReader(strB.ToString())) {
List<IElement> list = HTMLWorker.ParseToList(sReader, new StyleSheet());
foreach (IElement elm in list) {
document.Add(elm);
}
}
} catch (Exception ee) {
ee.ToString();
} finally {
document.Close();
}
}
protected void GeneratePDFAndDownload (object sender, EventArgs e) {
string fileName = "RetroCloud_" + proj_name + "_" + DateTime.Now.Ticks + ".pdf";
GeneratePDF("", fileName, true, "");
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.Flush();
Response.End();
}
ASCX Control:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="tagcloud.ascx.cs" Inherits="tagcloud" %>
<div style="padding-left: 25px; padding-right: 25px; text-align: center;">
<asp:listview runat="server" ID="ListView1" ItemPlaceholderID="itemPlaceHolder">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<%# Eval("Tag") %>
</ItemTemplate>
<EmptyDataTemplate>
<asp:Label ID="negative_tags" runat="server" style="color: #ff0000;" Text="[NO NEGATIVE TAGS FOUND]"></asp:Label>
</EmptyDataTemplate>
</asp:listview>
</div>
<br />
<div style="padding-left: 25px; padding-right: 25px; text-align: center;">
<asp:listview runat="server" ID="ListView2" ItemPlaceholderID="itemPlaceHolder">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<%# Eval("Tag") %>
</ItemTemplate>
<EmptyDataTemplate>
<asp:Label ID="positive_tags" runat="server" style="color: #33cc00;" Text="[NO POSITIVE TAGS FOUND]"></asp:Label>
</EmptyDataTemplate>
</asp:listview>
</div>
ASCX CS FILE:
string proj_id, proj_name, iteration;
protected void Page_Load(object sender, EventArgs e)
{
proj_name = Request.QueryString["project"].ToString();
proj_id = Request.QueryString["id"].ToString();
if (String.IsNullOrEmpty((string)Session["iteration"]))
iteration = "0";
else
iteration = (string)Session["iteration"];
BindTagCloud();
}
private void BindTagCloud()
{
int pro_id = Convert.ToInt32(proj_id);
int iteration_id = Convert.ToInt32(iteration);
....
if (iteration_id != 0)
{
ListView1.DataSource = tagCloudNegativeIteration;
ListView1.DataBind();
ListView2.DataSource = tagCloudPositiveIteration;
ListView2.DataBind();
}
else
{
ListView1.DataSource = tagCloudNegative;
ListView1.DataBind();
ListView2.DataSource = tagCloudPositive;
ListView2.DataBind();
}
"The Document has no pages" means you haven't actually written anything to the Document before calling document.close().
I suspect that if you set a breakpoint at the line where you call document.add(), you'll never hit it.
I suggest you take a long, hard look at the input and output to HTMLWorker.ParseToList(). I doubt it's what you expect.

Categories

Resources