filter class with stimulsoft - asp.net

I designed a report with stimul. In this report there's two types of filters. First one for filtering Date via two text box and other one for filtering class type via dropdown.
Both of them work correctly in stimulsoft designer but dropdown filtering doesn't work in asp.net web page.
http://8pic.ir/images/0klmctx0poxzfud6pjy0.png
public partial class Report : System.Web.UI.Page
{
EsmailEntities db = new EsmailEntities();
protected void Page_Load(object sender, EventArgs e)
{
DrpGrpPro();
}
protected void Button1_Click(object sender, EventArgs e)
{
string con = ConfigurationManager.ConnectionStrings["EsmailEntities"].ConnectionString;
string serverlocation = HttpContext.Current.Server.MapPath(string.Empty);
StiReport report = new StiReport();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("connection", con));
report.Load(serverlocation + "\\Reports\\ReportWithFiltermrt.mrt");
report.Dictionary.Variables["SC"].Value = DropDownList1.SelectedItem.Value;
report.Dictionary.Variables["FromDate"].Value = txtFromDate.Text;
report.Dictionary.Variables["ToDate"].Value = txtToData.Text;
}
void DrpGrpPro()
{
DropDownList1.DataTextField = "ClassName";
DropDownList1.DataValueField = "ClassId";
DropDownList1.DataSource = db.TblClass.ToList();
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("انتخاب کنید", "0"));
}
}

Related

DevExpress XtraReport HtmlItemCreated event not raised

I'm using DevExpress 2012 Vol 2.4 ASP.NET WebForms controls. I've created a new object of XtraReport class and subscribed to its HtmlItemCreated event. When I'm calling the ExportToHtml method of the XtraReport object the event is not getting raised.
I've not posted the markup but there is just a button. When I click the button the event is not triggered. I've put a breakpoint and tested that.
public partial class WebForm1 : System.Web.UI.Page
{
XtraReport rep = null;
protected void Page_Load(object sender, EventArgs e)
{
rep = new XtraReport();
rep.CreateDocument();
rep.HtmlItemCreated += rep_HtmlItemCreated;
PageHeaderBand h = new PageHeaderBand();
XRLabel l = new XRLabel();
l.Text = "asdasd";
h.Controls.Add(l);
rep.Bands.Add(h);
}
protected void rep_HtmlItemCreated(object sender, HtmlEventArgs e)
{
if (e.ScriptContainer != null)
{
string x = "asdasd";
}
}
protected void btnTest_Click(object sender, EventArgs e)
{
string sPDFFilePath = System.IO.Path.GetTempPath() + "Test.html";
HtmlExportOptions objPDFExpOpt = rep.ExportOptions.Html;
objPDFExpOpt.EmbedImagesInHTML = true;
objPDFExpOpt.ExportMode = HtmlExportMode.DifferentFiles;
if (!string.IsNullOrEmpty("Test"))
objPDFExpOpt.Title = "Test";
rep.ExportToHtml(sPDFFilePath, objPDFExpOpt);
}
}

How to declare public variable from protected method in asp net?

I have database with images in folder on my server. To display this images I'am using DataList control. ItemTemplate include also a LinkButton
<asp:LinkButton ID="wybierzZdjecieBtn" OnClick="choosePhotoButton_Click" CommandArgument='<%#Eval("PhotoLinkAddress")%>' CssClass="wybierzZdjecieButton" runat="server">Choose photo</asp:LinkButton>
To receiving Value from LinkButton CommandArgument i'am using this method:
protected void choosePhotoButton_Click(object sender, EventArgs e)
{
LinkButton button = (LinkButton)(sender);
string photoLinkAddressVar = button.CommandArgument.ToString();
Response.Write(PhotoLinkAddressVar);
}
This works fine, no problems. But this is not what I want achieve. My intentions is send this variable "PhotoLinkAddressVar" to this method:
protected void addNewNews_Click(object sender, EventArgs e)
{
string trescStatus = "czeka";
string autor = Session["userName"].ToString();
DateTime data = DateTime.Now;
string dataFormat = "";
dataFormat = data.ToString("dd/MM/yyyy H:mm");
string CS = ConfigurationManager.ConnectionStrings["wiadomosciConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
con.Open();
string dodaj = "Insert into News (TytulNews, TrescNews, Autor, Data, Kategoria, Dotyczy, PhotoLinkAddress, Status) values (#TytulNews, #TrescNews, #Autor, #Data, #Kategoria, #Dotyczy, #PhotoLinkAddress, #Status)";
SqlCommand com = new SqlCommand(dodaj, con);
com.Parameters.AddWithValue("#TytulNews", tytulNewsTextBox.Text);
com.Parameters.AddWithValue("#TrescNews", trescTextBox.Text);
com.Parameters.AddWithValue("#Autor", autor);
com.Parameters.AddWithValue("#Data", dataFormat);
com.Parameters.AddWithValue("#Kategoria", kategoria.SelectedValue.ToString());
com.Parameters.AddWithValue("#Dotyczy", dotyczy.SelectedValue.ToString());
com.Parameters.AddWithValue("#PhotoLinkAddress", photoLinkAddressVar);
com.Parameters.AddWithValue("#Status", trescStatus);
com.ExecuteNonQuery();
}
}
User have to choose photo before press "Add News", because if He doesn't do that, he will receive error message. I dont know, how do that. I Was trying declare some kind public variable before PageLoad and do something like this:
protected void choosePhotoButtonButton_Click(object sender, EventArgs e)
{
LinkButton button = (LinkButton)(sender);
photoLinkAddressVar = button.CommandArgument.ToString();
}
but that method won't declare the variable. Do You have any idea, how can I achieve that ?.
You could use also the ViewState.
protected void choosePhotoButton_Click(object sender, EventArgs e)
{
LinkButton button = (LinkButton)(sender);
string photoLinkAddressVar = button.CommandArgument.ToString();
View["photoLinkAddressVar"]=photoLinkAddressVar;
Response.Write(PhotoLinkAddressVar);
}
Then in the addNewNews_Click method, you coukld retrieve this value with the following way:
com.Parameters.AddWithValue("#PhotoLinkAddress", ViewState["photoLinkAddressVar"]);
For further documantation about ViewState please look here.

How to select Listbox value in asp.net

I have a ListBox in my webpage that is bound from database in this way:
ListBox1.DataTextField = "Text";
ListBox1.DataValueField = "MenuID";
ListBox1.DataSource = SqlHelper.ExecuteReader(DAL.DALBase.ConnectionString, "GetMenu");
ListBox1.DataBind();
I want to get selected item value and used this code but have a error and does not worked.
ListBox1.SelectedValue;
Forgive me if I have problems on how to write because my English is not good.
Can you be more specific on the error you are getting?
Using ListBox1.SelectedValue should work.
For example:
int mySelectedValue = int.Parse(ListBox1.SelectedValue);
or
string mySelectedValue = ListBox1.SelectedValue;
Edit
Added code to ensure the original poster was keeping values in ListBox databound.
protected void Page_Load( object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindListBox();
}
}
private BindListBox()
{
ListBox1.DataTextField = "Text";
ListBox1.DataValueField = "MenuID";
ListBox1.DataSource = SqlHelper.ExecuteReader(DAL.DALBase.ConnectionString, "GetMenu");
ListBox1.DataBind();
}
protected void SomeButton_Click( object sender, EventArgs e)
{
string mySelectedValue = ListBox1.SelectedValue;
}

problem in updating the textbox data into SQLSERVER

I have problem in updating user profile through asp:TextBox.
At the time of page load , all the textboxes get loaded with correct values from the database sqlserver.
say First name=SAM {i.e SAM is shown in txtName's textfield)
and Last Name=Berton
but when i alter the content of txtName to SAMANTHA
and similary for other textboxes, and click on update profile button, Internally txtName.text="SAM" gets retained notwithstanding the changed content of txtName.text="SAMANTHA" by manually altering the content of textbox.So same value that is "SAM" gets stored into the sqlserver rather than "SAMANTHA".
protected void Page_Load(object sender, EventArgs e)
{
loadProfileData();
}
protected void loadProfileData()
{
string connStringProfileload = ConfigurationManager.ConnectionStrings["myconnString"].ConnectionString;
SqlConnection conProfLoad = new SqlConnection(connStringProfileload);
conProfLoad.Open();
string emailAddLogin = User.Identity.Name.ToString();
string strSqlProfileLoad = "SELECT * FROM [gen_profile] WHERE [email]=#email";
SqlCommand cmd = new SqlCommand(strSqlProfileLoad, conProfLoad);
cmd.Parameters.AddWithValue("#email", emailAddLogin);
SqlDataReader drProfileLoad = cmd.ExecuteReader();
while (drProfileLoad.Read())
{
txtName.Text = drProfileLoad["fname"].ToString();
txtLastName.Text=drProfileLoad["lname"].ToString();
}
drProfileLoad.Close();
conProfLoad.Close();
}
protected void BtnUpdtProf_Click(object sender, EventArgs e)
{
string connStringProfileUpdate = ConfigurationManager.ConnectionStrings["myconnString"].ConnectionString;
SqlConnection conUpdateProf = new SqlConnection(connStringProfileUpdate);
conUpdateProf.Open();
string emailAddLogin = User.Identity.Name.ToString();
string strSqlUpdateProf = "UPDATE gen_profile SET fname =#fname, lname =#lname where email=#email;";
SqlCommand cmdUpdate = new SqlCommand(strSqlUpdateProf, conUpdateProf);
cmdUpdate.Parameters.AddWithValue("#fname", txtName.Text.ToUpper().Trim());
cmdUpdate.Parameters.AddWithValue("#lname", txtLastName.Text.ToUpper().Trim());
cmdUpdate.Parameters.AddWithValue("#email", emailAddLogin);
int i = cmdUpdate.ExecuteNonQuery();
conUpdateProf.Close();
if (i == 1)
Response.Redirect("~/prof/resp_update_prof.aspx");
}
Change this method :
protected void Page_Load(object sender, EventArgs e) {
loadProfileData();
}
to :
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) loadProfileData();
}
Basically, your textBox values are being reset in the page load event, so everytime your page posts back, it's resetting the values in the textboxes and then saving them back to the database.
This is because before your button click event, page_load get's fired which re-populates the textbox.
You can stop this happening by checking for a post back as follows:
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack)
{
loadProfileData();
}
}

Linking database column to dropdown control in ASP.Net

I am using c# with asp.net and SQL Server 2005 as backend. I want to use dropdown list control in a form to populate a textbox. The dropdown control is linked to a column in the database. How can I code this in c#?
Do you mean this
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.datasource = list;
DropDownList1.datBind();
}
protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.SelectedValue;
}
Or this
protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e)
{
TextBox t = new TextBox();
t.Text = DropDownList1.SelectedValue;
body.InnerHtml.add(t);
}

Resources