crystal report parameter incorrect - c#

Two Crystal reports
CrystalReport1.rpt
employeemonthly.rpt
Call these reports on signal aspx.net page.
protected void Button1_Click1(object sender, EventArgs e)
{
if (Page.IsValid)
{
if (rd.SelectedValue == "1")
{
DateTime to = Convert.ToDateTime(sdate.Text);
dbconnect a = new dbconnect();
ReportDocument rDoc = new ReportDocument();
a.OpenConnection();
a.cmd = new SqlCommand("viewattandace_repoeting",a.con);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
a.cmd.CommandType = CommandType.StoredProcedure;
da.SelectCommand = a.cmd;
da.Fill(ds, "viewattandace_repoeting");
rDoc.Load(Server.MapPath("CrystalReport1.rpt"));
rDoc.SetDataSource(ds);
rDoc.SetParameterValue("date", to);
rDoc.SetParameterValue("depid", 1);
CrystalReportViewer1.ReportSource = rDoc;
CrystalReportViewer1.DataBind();
a.CloseConnection();
CleartextBoxes(this);
}
else
if (rd.SelectedValue == "2")
sd = Convert.ToDateTime(m.SelectedItem.Text + "/" + "1" + "/" + yt.SelectedItem.Text);
ed = LastDayOfMonth(sd);
dbconnect a = new dbconnect();
using (ReportDocument rDoc = new ReportDocument())
{
a.OpenConnection();
a.cmd = new SqlCommand("viewattandace_repoeting", a.con);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
a.cmd.CommandType = CommandType.StoredProcedure;
da.SelectCommand = a.cmd;
da.Fill(ds, "viewattandace_repoeting");
rDoc.Load(Server.MapPath("employeemonthly.rpt"));
rDoc.SetDataSource(ds);
rDoc.SetParameterValue("sdate", sd);
rDoc.SetParameterValue("edate", ed);
rDoc.SetParameterValue("depid", 1);
rDoc.SetParameterValue("email", eet.Text.Trim());
CrystalReportViewer1.ReportSource = rDoc;
CrystalReportViewer1.DataBind();
a.CloseConnection();
}
}
}
}
view only one report at a time which dropdownlist selected index.
Now problem is view only first time selected report . when i selected other report then show this "parameter incorrect".
For Example
I selected CrystalReport1 report in dropdownlist and click button .Then report view ,then I selected employeemonthly report and click button then show this "parameter incorrect" and Vice versa.

I can solved this by add new CrystalReportViewer control
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (rd.SelectedValue == "1")
{
CrystalReportViewer2.Visible = false;
yl.Visible = false;
yt.Visible = false;
}
if (rd.SelectedValue == "2")
{
CrystalReportViewer1.Visible = false;
sdate.Visible = false;
}
}
**Button click code **
protected void Button1_Click1(object sender, EventArgs e)
{
if (Page.IsValid)
{
if (rd.SelectedValue == "1")
{
CrystalReportViewer1.Visible = true;
DateTime to = Convert.ToDateTime(sdate.Text);
dbconnect a = new dbconnect();
ReportDocument rDoc = new ReportDocument();
a.OpenConnection();
a.cmd = new SqlCommand("viewattandace_repoeting", a.con);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
a.cmd.CommandType = CommandType.StoredProcedure;
da.SelectCommand = a.cmd;
da.Fill(ds, "viewattandace_repoeting");
rDoc.Load(Server.MapPath("CrystalReport1.rpt"));
rDoc.SetDataSource(ds);
rDoc.SetParameterValue("date", to);
rDoc.SetParameterValue("depid", 1);
CrystalReportViewer1.ReportSource = rDoc;
CrystalReportViewer1.DataBind();
CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
a.CloseConnection();
}
else
if (rd.SelectedValue == "2")
{
CrystalReportViewer2.Visible = true;
sd = Convert.ToDateTime(m.SelectedItem.Text + "/" + "1" + "/" + yt.SelectedItem.Text);
ed = LastDayOfMonth(sd);
dbconnect a = new dbconnect();
ReportDocument rDoc = new ReportDocument();
a.OpenConnection();
a.cmd = new SqlCommand("viewattandace_repoeting", a.con);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
a.cmd.CommandType = CommandType.StoredProcedure;
da.SelectCommand = a.cmd;
da.Fill(ds, "viewattandace_repoeting");
rDoc.Load(Server.MapPath("employeemonthly.rpt"));
rDoc.SetDataSource(ds);
rDoc.SetParameterValue("sdate", sd);
rDoc.SetParameterValue("edate", ed);
rDoc.SetParameterValue("depid", 1);
rDoc.SetParameterValue("email", eet.Text.Trim());
CrystalReportViewer2.ReportSource = rDoc;
CrystalReportViewer2.DataBind();
CrystalReportViewer2.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
a.CloseConnection();
}
}

Please change if part of you code to
ReportDocument rDoc = new ReportDocument())
as you have it in else part

Related

C# How to Save multiple rows from Datagridview to One Database

I have 2 datagridview and need to save them in one database.
I don't know how to explain this, but here I link the video I made directly from my desktop.
Youtube video link
And here my Save Button code for this form.
{
public Invoices()
{
InitializeComponent();
}
MySqlConnection Connection = new MySqlConnection("server=localhost; database=lmsdb; user=root; password=; pooling = false; convert zero datetime=True");
//MySqlConnection Connection = new MySqlConnection("server=35.186.146.59;database=lmsdb;uid=lmsdb;pwd=dbserver; pooling = false; convert zero datetime=True");
BindingSource bsInvoices = new BindingSource();
private void Invoices_Load(object sender, EventArgs e)
{
BindGrid();
}
private void BindGrid()
{
MySqlConnection Connection = new MySqlConnection("server=localhost; database=lmsdb; user=root; password=; pooling = false; convert zero datetime=True");
//Connection.Open();
MySqlCommand Command = new MySqlCommand("Select * From invoicesdb", Connection);
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(Command);
da.Fill(dt);
dgvInvoiceList.DataSource = null;
dgvInvoiceList.AllowUserToAddRows = false;
dgvInvoiceList.AutoGenerateColumns = false;
dgvInvoiceList.ColumnCount = 16;
dgvInvoiceList.Columns[0].HeaderText = "ID";
dgvInvoiceList.Columns[0].DataPropertyName = "id";
dgvInvoiceList.Columns[1].HeaderText = "Client Name";
dgvInvoiceList.Columns[1].DataPropertyName = "ClientName";
dgvInvoiceList.Columns[2].HeaderText = "References No";
dgvInvoiceList.Columns[2].DataPropertyName = "ReferencesNo";
dgvInvoiceList.Columns[3].HeaderText = "Case No";
dgvInvoiceList.Columns[3].DataPropertyName = "CaseNo";
dgvInvoiceList.Columns[4].HeaderText = "NRIC No";
dgvInvoiceList.Columns[4].DataPropertyName = "NRICNo";
dgvInvoiceList.Columns[5].HeaderText = "GST No";
dgvInvoiceList.Columns[5].DataPropertyName = "GSTNo";
dgvInvoiceList.Columns[6].HeaderText = "Invoices Date";
dgvInvoiceList.Columns[6].DataPropertyName = "InvoicesDate";
dgvInvoiceList.Columns[7].HeaderText = "Invoices Tax No";
dgvInvoiceList.Columns[7].DataPropertyName = "InvoicesTaxNo";
dgvInvoiceList.Columns[8].HeaderText = "Issue Date";
dgvInvoiceList.Columns[8].DataPropertyName = "IssueDate";
dgvInvoiceList.Columns[9].HeaderText = "Due Date";
dgvInvoiceList.Columns[9].DataPropertyName = "DueDate";
dgvInvoiceList.Columns[10].HeaderText = "Legal Fees";
dgvInvoiceList.Columns[10].DataPropertyName = "LegalFees";
dgvInvoiceList.Columns[11].HeaderText = "Stage";
dgvInvoiceList.Columns[11].DataPropertyName = "StageSchedule";
dgvInvoiceList.Columns[12].HeaderText = "Description";
dgvInvoiceList.Columns[12].DataPropertyName = "Description";
dgvInvoiceList.Columns[13].HeaderText = "Legal Fees Total";
dgvInvoiceList.Columns[13].DataPropertyName = "LegalFeesTotal";
dgvInvoiceList.Columns[14].HeaderText = "Disbursement Total";
dgvInvoiceList.Columns[14].DataPropertyName = "DisbursementTotal";
dgvInvoiceList.Columns[15].HeaderText = "Grand Total";
dgvInvoiceList.Columns[15].DataPropertyName = "GrandTotal";
dgvInvoiceList.Columns[0].Visible = false;
dgvInvoiceList.DataSource = dt;
Connection.Close();
MySqlConnection Connection2 = new MySqlConnection("server=localhost; database=lmsdb; user=root; password=; pooling = false; convert zero datetime=True");
//Connection.Open();
MySqlCommand Command2 = new MySqlCommand("Select * From invoicesdb", Connection2);
DataTable dt2 = new DataTable();
MySqlDataAdapter da2 = new MySqlDataAdapter(Command2);
da2.Fill(dt2);
dgvDisList.DataSource = null;
dgvDisList.AllowUserToAddRows = false;
dgvDisList.AutoGenerateColumns = false;
dgvDisList.ColumnCount = 2;
dgvDisList.Columns[0].HeaderText = "Description";
dgvDisList.Columns[0].DataPropertyName = "DisbursementDescription";
dgvDisList.Columns[1].HeaderText = "Amount";
dgvDisList.Columns[1].DataPropertyName = "DisbursementAmount";
dgvDisList.DataSource = dt2;
Connection2.Close();
}
private void btnSave_Click(object sender, EventArgs e)
{
MySqlConnection Connection = new MySqlConnection("server=localhost; database=lmsdb; user=root; password=; pooling = false; convert zero datetime=True");
for (int i = 0; i < dgvDisList.Rows.Count; i++)
{
string disDescription = dgvDisList.Rows[i].Cells[0].Value.ToString();
string disAmount = dgvDisList.Rows[i].Cells[1].Value.ToString();
MySqlCommand cmd = new MySqlCommand($"INSERT INTO invoicesdb (id, ClientName, ReferencesNo, CaseNo, NRICNo, GSTNo, InvoicesDate, InvoicesTaxNo, IssueDate, DueDate, LegalFees, StageSchedule, Description, DisbursementDescription, DisbursementAmount, LegalFeesTotal, DisbursementTotal, GrandTotal) Values ('{tbID.Text}', {tbClientName.Text}','{tbReferencesNo.Text}','{tbCaseNo.Text}','{tbNRICNo.Text}','{tbGST.Text}','{dateInvoice.Text}','{tbInvoiceTaxNo.Text}','{dateIssue.Text}','{dateDue.Text}', '{tbLegalFees.Text}','{cbStageSchedule.Text}','{tbDescription.Text}','{ disDescription }','{ disAmount }','{tbTotalLegalFees.Text}','{tbTotalDisbursement.Text}','{tbGrandTotal.Text}')", Connection);
Connection.Open();
cmd.ExecuteNonQuery();
Connection.Close();
}
Invoices_Load(sender, e);
MessageBox.Show("Saved Successfully");
btnNew_Click(sender, e);
}
}
}
You will need to import the following namespaces.
using System.Data;
using System.Data.SqlClient;
Inside the Form Load event, the DataGridView is populated with a dynamic DataTable
private void Form1_Load(object sender, EventArgs e)
{
this.BindDataGridView();
}
private void BindDataGridView()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new .....
a loop is executed over the DataGridView rows. Inside the loop, the values from each column (cell) of the DataGridView are fetched and the record is inserted into the database table.

Dynamically Binded Dropdownlist always taking first value when get by ddl.SelectedValue

I have a dynamically bind dropdownlist from which i want insert selected value in a table. But when I submit the form it is taking the very first value of dropdownlist not the selected value and inserts the first value of the dropdownlist.
Here is my code
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(connection.getConnection()))
{
string sqlGetClass = "select pk_classID,brachName+'-'+classYear as classInfo from tbl_studentClass";
SqlCommand cmdGetClass = new SqlCommand(sqlGetClass, conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmdGetClass);
DataSet ds = new DataSet();
da.Fill(ds);
ddlClass.DataSource = ds;
ddlClass.DataTextField = "classInfo";
ddlClass.DataValueField = "pk_classID";
ddlClass.DataBind();
ddlClass.Items.Insert(0, new ListItem("--SELECT--", ""));
conn.Close();
}
}
protected void btnStdRegisterSubmit_Click(object sender, EventArgs e)
{
string dateOfBirth = txtStdDOBYear.Text+"-"+ddlStdDOBMonth.SelectedValue + "-"+txtStdDOBDate.Text;
using (SqlConnection conn = new SqlConnection(connection.getConnection()))
{
string sqlInsertStd = "Insert into tbl_studentRegistration (firstName,surname,studentUsername,studentPassword,studentDOB,studentGender,studentMobile,class) values(#firstName,#surname,#studentUsername,#studentPassword,#studentDOB,#studentGender,#studentMobile,#class)";
conn.Open();
SqlCommand cmdInsertStd = new SqlCommand(sqlInsertStd, conn);
cmdInsertStd.Parameters.AddWithValue("#firstName", txtStdFirstName.Text);
cmdInsertStd.Parameters.AddWithValue("#surname", txtStdSurname.Text);
cmdInsertStd.Parameters.AddWithValue("#studentUsername", txtStdUsername.Text);
cmdInsertStd.Parameters.AddWithValue("#studentPassword", txtStdPassword.Text);
cmdInsertStd.Parameters.AddWithValue("#studentDOB", DateTime.Parse(dateOfBirth).ToString("yyyy-MM-dd"));
cmdInsertStd.Parameters.AddWithValue("#studentGender", ddlStdGender.SelectedValue.ToString());
cmdInsertStd.Parameters.AddWithValue("#studentMobile", txtStdMobile.Text);
cmdInsertStd.Parameters.AddWithValue("#class", ddlClass.SelectedValue);
cmdInsertStd.ExecuteNonQuery();
conn.Close();
txtStdFirstName.Text = "";
txtStdSurname.Text = "";
txtStdUsername.Text = "";
ddlClass.SelectedValue = "";
txtStdPassword.Text = "";
txtStdConfirmPassword.Text = "";
ddlStdDOBMonth.SelectedValue = "";
txtStdDOBDate.Text = "";
txtStdDOBYear.Text = "";
ddlStdGender.SelectedValue = "";
txtStdMobile.Text = "";
Response.Redirect("~/index.aspx");
}
}
Please help I am new to asp.net
Problem : You are adding the items into DropDownList for every Page request as your code added in Page_Load EventHandler. so the DropDownList always contain the first item as selectedItem even though you selected different item.
Solution: You need to append the items into DropDownList only when page is Loaded but not on every PostBack request.
You can use Page.IsPostBack to identify wether page request is PostBack request or not.
Try This:
if(!Page.IsPostBack)
{
using (SqlConnection conn = new SqlConnection(connection.getConnection()))
{
string sqlGetClass = "select pk_classID,brachName+'-'+classYear as
classInfo from tbl_studentClass";
SqlCommand cmdGetClass = new SqlCommand(sqlGetClass, conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmdGetClass);
DataSet ds = new DataSet();
da.Fill(ds);
ddlClass.DataSource = ds;
ddlClass.DataTextField = "classInfo";
ddlClass.DataValueField = "pk_classID";
ddlClass.DataBind();
ddlClass.Items.Insert(0, new ListItem("--SELECT--", ""));
conn.Close();
}
}
Page_Load executes every time the page posts back, such as when you click your submit button. You should put your using stateme3nt in a
conditional:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
using (SqlConnection conn = new SqlConnection(connection.getConnection()))
{
string sqlGetClass = "select pk_classID,brachName+'-'+classYear as classInfo from tbl_studentClass";
SqlCommand cmdGetClass = new SqlCommand(sqlGetClass, conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmdGetClass);
DataSet ds = new DataSet();
da.Fill(ds);
ddlClass.DataSource = ds;
ddlClass.DataTextField = "classInfo";
ddlClass.DataValueField = "pk_classID";
ddlClass.DataBind();
ddlClass.Items.Insert(0, new ListItem("--SELECT--", ""));
conn.Close();
}
}
}
So that your list is not repopulated every time you click your submiit button.
(you should consider putting the list population code in a separate method)

how to convert words from a string into dropdown list dataitems asp.net

in assign.aspx page i have
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected)
{
str1+=li.Value+" ";
}
}
sql = " insert into assgnmovie values ('"+mvnm+"','"+thnm+"','"+date+"','"+str1+"')";
SqlDatabase.Insert(sql);
}
now in booking.aspx page
protected void ddlMov_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter("select thname from assgnmovie where mvname='"+ddlMov.SelectedItem.Value+"'",con);
adp.Fill(ds);
ddlTheater.DataSource = ds;
ddlTheater.DataValueField = "thname";
ddlTheater.DataBind();
ddlTheater.Items.Insert(0, new ListItem("SELECT", "0"));
}
protected void ddlTheater_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter("select showtime from assgnmovie where mvname='"+ddlMov.SelectedItem.Value+"' and thname='"+ddlTheater.SelectedItem.Value+"'",con);
String a = adp.ToString();
String b = a.Substring(1, 6);
ddlShow.Text = b;
adp.Fill(ds);
how do i split the string and make the words as dataset for ddlshow.list???
Try something like this:
protected void ddlTheater_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter("select showtime from assgnmovie where mvname='"+ddlMov.SelectedItem.Value+"' and thname='"+ddlTheater.SelectedItem.Value+"'",con);
String a = adp.ToString();
String b = a.Substring(1, 6);
ddlShow.Text = b;
adp.Fill(ds);
ddlTheater.DataSource = ds;
ddlTheater.DataValueField = "showtime";
ddlTheater.DataBind();
}

Filter on Datagridview

I am working on Datagridview filtering according to checkbox(yes/no) which is in access database.
my code ---------------------------------------
{
OleDbConnection baglanti = new OleDbConnection(#"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Burak YEŞİLYURT\Desktop\secret.accdb");
OleDbCommand komutcu;
OleDbDataAdapter adpt;
DataSet ds;
public Form1()
{
InitializeComponent();
baglanti.Open();
komutcu = new OleDbCommand("SELECT * FROM todo", baglanti);
adpt = new OleDbDataAdapter(komutcu);
ds = new DataSet();
adpt.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
adpt.RowUpdated += adpt_RowUpdated;
this.dataGridView1.Columns["id"].Visible = false;
this.dataGridView1.Columns["zaman"].Visible = false;
this.dataGridView1.Columns["todo"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
private void Form1_Load(object sender, EventArgs e)
{
baglanti.Open();
komutcu = new OleDbCommand("SELECT * FROM todo", baglanti);
adpt = new OleDbDataAdapter(komutcu);
ds = new DataSet();
adpt.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
public void adpt_RowUpdated(object sender, OleDbRowUpdatedEventArgs e)
{
if (e.RecordsAffected == 0)
{
e.Row.RowError = "Tutarlılık ihlali: UpdateCommand, beklenen 1 kaydın 0 kaydını etkiledi.";
// Hatalı satır üzerinde işlem yapılmadan es geçiliyor.
e.Status = UpdateStatus.SkipCurrentRow;
}
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
OleDbCommandBuilder komut = new OleDbCommandBuilder(adpt);
DataSet yeni = new DataSet();
yeni = ds.GetChanges(DataRowState.Modified | DataRowState.Added);
adpt.Update(yeni.Tables[0]);
}
private void only_cntr_CheckStateChanged(object sender, EventArgs e)
{
ds.Tables["todo"].DefaultView.RowFilter = "state = 'true'"; //// Error this line
}
when I debbug I recieved this error "Object reference not set to an instance of an object."
Where I'm missing? Any help I'll be pleasure. Thanks
Surely you mean "state = true" or "state =-1" A boolean cannot be set to a text value.

different window.open opens the same page

I am using window.open to open 2 different pages in pop-up windows,but for some reason both the triggers opens the same page in the pop-up window,heres how I am trying to do this:
first:
Response.Write("<script type='text/javascript'>window.open('TransEditEntry.aspx','mywindow','width=850px,height=300px,left=0,top=10,screenX=100,screenY=10')</script>");
second:
Response.Write(#"<script type='text/javascript'>window.open('TransNewEntry.aspx','','width=850px,height=300px,left=0,top=10,screenX=100,screenY=10')</script>");
this opens 'TransEditEntry.aspx' page instead of 'TransNewEntry.aspx'`
here the rest of the code:
The entire function which is called on add button click:
protected void addNew(object sender, EventArgs e)
{
//HiddenField sr = (HiddenField)GridView1.SelectedRow.Cells[6].FindControl("srno");
//Session["TransSrNo"] = sr.Value;
Response.Write(#"<script type='text/javascript'>window.open('TransNewEntry.aspx','','width=850px,height=300px,left=0,top=10,screenX=100,screenY=10')</script>");
//Session["transAdd"] = "1";
}
The add button which calls the function:
<asp:Button ID="AddBtn" runat="server" OnClick="addNew" Text="Add"/>
The page TransNewEntry.aspx.cs
public partial class TransEditEntry : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(GetConnectionString.Get());
string subCode;
DataTable dt;
SqlDataAdapter sda;
SqlCommandBuilder build;
DataRow dr;
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
Response.Write((Session["TransSrNo"]).ToString());
int SRno = Convert.ToInt32((Session["TransSrNo"]).ToString());
con.Open();
SqlCommand cmd3 = new SqlCommand("select sub_code from tran_dtls where sr_no='" + SRno + "'", con);
subCode = (string)cmd3.ExecuteScalar();
con.Close();
if (!IsPostBack)
{
sda = new SqlDataAdapter("select * from tran_dtls where sr_no=" + SRno + "", con);
build = new SqlCommandBuilder(sda);
dt = new DataTable();
sda.Fill(dt);
foreach (DataRow row in dt.Rows)
{
srNoTxt.Text = "";
amttxt.Text = "";
partTxt.Text = "";
checkNoTxt.Text = "";
checkDtTxt.Text = "";
refNoTxt.Text = "";
refDtTxt.Text = "";
jobNoTxt.Text = "";
}
}
}
protected void GlChange(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd4 = new SqlCommand("select ac_type from ac_mstr where AC_desc='" + GlDrp.SelectedValue + "'", con);
string acType = (string)cmd4.ExecuteScalar();
SqlCommand cmd5 = new SqlCommand("select gl_code from ac_mstr where AC_desc='" + GlDrp.SelectedValue + "'", con);
string gl_code = (string)cmd5.ExecuteScalar();
if (acType == "S")
{
SqlDataSource3.SelectCommand = ("select ac_desc from ac_mstr where gl_code='" + gl_code + "'");
subDrp.DataBind();
subDrp.Enabled = true;
//Response.Write("<script type='javacript/text'>alert('1')</script>");
}
else
{
subDrp.Enabled = false;
//Response.Write("<script type='javacript/text'>alert('2')</script>");
}
con.Close();
}
protected void saveRow(object sender, EventArgs e)
{
int SRno = Convert.ToInt32((Session["TransSrNo"]).ToString());
sda = new SqlDataAdapter("select * from tran_dtls where tc='" + Session["TC"] + "' and doc_no='" + Session["docNo"] + "' ", con);
build = new SqlCommandBuilder(sda);
//dt = new DataTable();
// DataSet ds = new DataSet();
sda.Fill(ds);
dt = (DataTable)ViewState["myViewState"];
if (Session["gridRow"] == null)
{
dt = ds.Tables[0];
dr = dt.NewRow();
dr["GL_code"] = GlDrp.SelectedValue;
dr["sub_code"] = subDrp.SelectedValue;
dr["particulars"] = partTxt.Text;
dr["chq_no"] = checkNoTxt.Text;
dr["chq_dt"] = checkDtTxt.Text;
dr["ref_no"] = refNoTxt.Text;
dr["ref_dt"] = refDtTxt.Text;
dr["dbcr"] = dbcrDrp.SelectedValue.ToString().Substring(0, 1);
dr["amt"] = amttxt.Text;
dr["job_no"] = jobNoTxt.Text;
dr["EMP"] = empDrop.SelectedValue;
dt.Rows.Add(dr);
dt.AcceptChanges();
ViewState["myViewState"] = dt;
//Session["gridRow"] = dt;
Session["gridRow"] = dt;
Session["saveToggle"] = "1";
closeFunction();
Response.Write("<script type='text/javascript'>this.close()</script>");
}
else
{
dt = (DataTable)Session["gridRow"];
dr = dt.NewRow();
dr["GL_code"] = GlDrp.SelectedValue;
dr["sub_code"] = subDrp.SelectedValue;
dr["particulars"] = partTxt.Text;
dr["chq_no"] = checkNoTxt.Text;
dr["chq_dt"] = checkDtTxt.Text;
dr["ref_no"] = refNoTxt.Text;
dr["ref_dt"] = refDtTxt.Text;
dr["dbcr"] = dbcrDrp.SelectedValue.ToString().Substring(0, 1);
dr["amt"] = amttxt.Text;
dr["job_no"] = jobNoTxt.Text;
dr["EMP"] = empDrop.SelectedValue;
dt.Rows.Add(dr);
dt.AcceptChanges();
ViewState["myViewState"] = dt;
//Session["gridRow"] = dt;
Session["gridRow"] = dt;
Session["saveToggle"] = "1";
//Response.Write("<script type='text/javascript'>window.opener.location.reload(true);</script>");
closeFunction();
Response.Write("<script type='text/javascript'>this.close()</script>");
}
}
private void closeFunction()
{
StringBuilder sb = new StringBuilder();
sb.Append("window.opener.RefreshPage();");
sb.Append("window.close();");
ClientScript.RegisterClientScriptBlock(this.GetType(), "CloseWindowScript", sb.ToString(), true);
}
}
Check your condition where you are doing : Response.Write. Both the conditions must be pointing out for first>

Categories