ReportViewer.Find not working - asp.net

I have a textbox, and a link button. On the same page I have a reportviewer.
The reportviewer is in updatepanel with linkbutton as async postback trigger.
I'm trying to find string (entered in textbox) in the report; when linkbutton is hit.
protected void lbtnFind_Click(object sender, EventArgs e)
{
ReportViewer1.Find(txtSearch.Text.Trim(), 1);
}
But that line gives error: Some parameters or credentials have not been specified Please help.

If txtSearch is a control you added, it will not be inside ReportViewer1.
If txtSearch is a control inside your ContentTemplate you should be searching in that control as follows:
var txtSrch = (TextBox)myUpdatePanel.ContentTemplate.Controls.FindControl("txtSearch");
You can get the text value from there and then set the parameters for the ReportViewer1 and refresh it.
ReportParameter[] parameters = new ReportParameter[1];
parameters[0] = new ReportParameter("Search", txtSrch.Text);
ReportViewer1.LocalReport.SetParameters(parameters);
ReportViewer1.RefreshReport();

Related

Why would formview disappear in Edit Mode

I know I must be missing something simple but I cannot find it so I will pose the question here. I have a formview with two templates (item and edititem).
The form is bound to the itemtemplate in the page_Load event and works fine. However, if is use !IsPostBack in the code-behind, the formview disappears when the edit button is clicked. If I remove the postback check from page_load, then the form view appears after the edit button is clicked.
The page does have viewstate enabled.
In general, what steps are needed to get the formview to transition between modes correctly?
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
source = Session["Source"].ToString();
acctType = Session["AccountType"].ToString();
acctNumber = Convert.ToInt32(Session["AccountNumber"]);
if (source == "LifeLineDS")
{
ObjectDataSource fvObjDS = new ObjectDataSource();
fvObjDS.TypeName = "LifelineDataAccess.LifelineSubscriber";
fvObjDS.SelectMethod = "GetLifelineDSSubscriber";
fvObjDS.SelectParameters.Add(new Parameter("AcctType", TypeCode.String, acctType));
fvObjDS.SelectParameters.Add(new Parameter("AcctNumber", TypeCode.String, Session["AccountNumber"].ToString()));
fvObjDS.DataBind();
if (fvObjDS != null)
{
fvSubscriber.DataSource = fvObjDS; //subscriber.ToString();
fvSubscriber.DataBind();
initialProgramValue = (fvSubscriber.FindControl("txtEligibility") as TextBox).Text;
}
}
// more code for other sources...
}
protected void btnEdit_Click(object sender, EventArgs e)
{
fvSubscriber.ChangeMode(FormViewMode.Edit);
fvSubscriber.DataSource = Session["subscriber"]; //Adding this line resolved !IsPostBack problem
fvSubscriber.DataBind();
ObjectDataSource programsObjDS = new ObjectDataSource();
programsObjDS.TypeName = "LifelineDataAccess.LifelineSubscriber";
programsObjDS.SelectMethod = "GetPrograms";
DropDownList ddlEligibility = ((DropDownList)(fvSubscriber.FindControl("ddlEligibility")));
if (ddlEligibility != null)
{
ddlEligibility.DataSource = programsObjDS;
ddlEligibility.DataTextField = "ProgramName";
ddlEligibility.DataValueField = "ProgramName";
ddlEligibility.SelectedValue = initialProgramValue; // Set selected value to subscribers current program
ddlEligibility.DataBind();
}
}
This
fvSubscriber.ChangeMode(FormViewMode.Edit);
fvSubscriber.DataBind();
seems to not to set the data source. The rule is that either you have the DataSourceID set in the declarative part of your code (*.aspx, *.ascx) and the binding is done automatically upon each postback OR you bind programmatically which involves setting the data source and calling the DataBind().
My recommendation would be to move your ObjectDataSource to the declarative part of the code and set the DataSourceID on the FormView to the ID of the ObjectDataSource. This is clean and easy and the binding works always.

Refreshing report inside dynamically created TabPanel

I am having a ReportViewer inside the inner TabContainer TabPanel which i generated dynamically in Page Init event.
I load the report on OnActiveTabChanged event and I want to refresh the report on SelectedIndexChanged event.
How ever report doesn't change when I change the selected value of the DropDownList.
Note: I debug and the loadReport inside the SelectedIndexChanged execute properly.
Following is part of my code.
protected void DDL_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList DDL = (DropDownList)sender;
ReportViewer rptViewer = (ReportViewer)DDL.Parent.FindControl("rptDateElectricity");
if (rptViewer == null)
{
rptViewer = new ReportViewer();
rptViewer.ID = "rpt" + "Date" + "Electricity"
rptViewer.Width = Unit.Pixel(1100);
loadReport(rptViewer, DDL, "Electricity", "Date");
DDL.Parent.Controls.Add(rptViewer);
}
}
protected void TCInner_OnActiveTabChanged(object sender, EventArgs e)
{
..............................
..............................
ReportViewer rptViewer = (ReportViewer)DDL.Parent.FindControl("rptDateElectricity");
if (rptViewer == null)
{
rptViewer = new ReportViewer();
rptViewer.ID = "rpt" + "Date" + "Electricity"
rptViewer.Width = Unit.Pixel(1100);
loadReport(rptViewer, DDL, "Electricity", "Date");
loadReport(rptViewer, DDL, monitoringObject, timePeriod);
}
}
}
I believe that this is a problem with view state.
I tried to set the EnableViewState false for the report viewer.
When i did i got the following runtime error:
"Microsoft JScript runtime error:
Sys.WebForms.PageRequestManagerServerErrorException: The Update
method can only be called on UpdatePanel with ID 'ReportArea' before
Render." Can anybody give a solution to this.
Thanks in advanced.
I got the same error when I told my report to autoRefresh, and it was caused by some javascript I'd inserted to override some of the ReportViewer's javascript (Microsoft.Reporting.WebFormsClient._ReportAreaAsyncLoad) to fix an error I'd been getting earlier. My custom javascript was triggering extra async load postbacks. I guess autorefresh conflicts with that.
Not sure if that's the cause of your problem though.

ASP.NET: TextBox.Text doesn't have updated value

I have an initialize function that loads data into my textbox NameTextBox, and then I add an "s" to the name. I then click the Save button that executes SaveButton_Click when debugging the value for NameTextBox.Text is still the original string (FirstName) and not (FirstNames). Why is this? Thanks.
Edit: Sorry here you go let me know if you need more...
Page_Load(sender, e)
Info = GetMyInfo()
Initialize()
Initialize()
NameTextBox.Text = Info.Name
SaveButton_Click(sender, e)
Dim command As SqlCommand
command = GetSQLCommand("StoredProcedure")
command.Parameters.AddWithValue("#Paramter", NameTextBox.Text)
ExecuteSQLCommand(command)
If the textbox is disabled it will not be persisted back to the codebehind, also if you set the initial value everytime (regardless of IsPostBack) you are essentially over writing what the value is when it gets to the Event handler (SaveButton_Click). Ex:
page_load() { NameTextBox.Text = "someValue";}
....
saveButton_Click() { string x = NameTextBox.Text;}
The above code will always have the text value of the textbox be "someValue". You would need to wrap it in an if(!IsPostBack) like so....
page_load() { if(!IsPostBack) {NameTextBox.Text = "someValue";}}
....
saveButton_Click() { string x = NameTextBox.Text;}

Dynamically update dropdownlist

I have this dropdownlist populated and everything. The only problem is that whenever I add a new item in the database through my website, the dropdownlist doesn't update for some reason.
private CurrentUser _cu = new CurrentUser();//just to check if use is an admin or not.
protected void Page_Load(object sender, EventArgs e)
{
_cu = (CurrentUser)Session[Common.SessVariables.CurUser];
if (!_cu.CanReport) { Response.Redirect("~/default.aspx"); }
CurrentUser cu = (CurrentUser)Session[Common.SessVariables.CurUser];
if (!IsPostBack)
{
foreach (PrefixAdd loc in cu.Prefix)//Prefix is a Property
{
ListItem x = new ListItem(loc.Prefix);
PrefixID.Items.Add(x);
}
}
}
#Wayne I'm using a store procedure to just insert a Prefix like Pre,yes,sey, etc. Then the list is populated with prefixes.
StringBuilder sbSQL = new StringBuilder(255);
sbSQL.Append(string.Format("exec insPrefix #Prefix=N'{0}';", PrefixBox.Text.Trim()));
string msg = string.Empty;
msg = (_oDAW.ExecuteNonQuery(sbSQL.ToString())) ? string.Format(Common.GetAppSetting(Common.ConfigKeys.User_Submit_Success),
PrefixBox.Text.Trim()) : Common.GetAppSetting(Common.ConfigKeys.SubmitFail); //this is a somewhat custom method for CS and databinding.
# Yuriy Rozhovetskiy Yea I add new items to this page with the dropdownlist.
Whenever you add an item to your database, you have to rebind your drop down list.
yourDropDown.DataSource = //...
yourDropDown.DataBind();
That is, DropDownLists (and other controls) have no way of knowing that their data has changed behind the scenes, they can't automatically detect it. You have to tell the controls to rebind their data manually.
Good job on the Page_Load(...){ if !(IsPostback) part.
Since you add new prefix on this page with some postback item you need to add this new item to PrefixID dropdown's Items collection and update the CurrentUser instance in Session right after you have add new prefix to database.

ASP.Net Gridview Update event

I have created a custom event to handle how the data should be updated in my gridview. The problem is, it is not firing. I have used debug mode and not even the breakpoint comes into effect when I click the update button.
Here is the event handler I have written:
protected void DocView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
var rw = DocView.Rows[e.RowIndex] ;
var Doc = (TextBox)rw.FindControl("DocTB");
var Num = (TextBox)rw.FindControl("NumberTB");
var Iss = (TextBox)rw.FindControl("IssuedTB");
var Exp = (TextBox)rw.FindControl("ExpiryTB");
var Stat = (TextBox)rw.FindControl("StatusTB");
var con = new LinqDBDataContext();
var doc = (from i in con.Documents
where i.DocumentID == e.RowIndex
select i).Single();
doc.DocumentType = Doc.Text;
doc.Number = Num.Text;
doc.Issued = DateTime.Parse(Iss.Text);
doc.Expiry = DateTime.Parse(Exp.Text);
doc.Status = Stat.Text;
con.SubmitChanges();
DocView.EditIndex = -1;
}
The event just will not fire!
Sounds like your missing some plumbing!
Are you using some type of development kit such as Visual Studio?
Usually these kit's will do most of the plumbing for you. Be aware, there is a little more to wiring up the event handler than just providing the following function:
protected void DocView_RowUpdating(object sender, GridViewUpdateEventArgs e)
If your in Visual Studio, try clicking the lightning bolt on the GridView's property page to take a look at the event handlers for it.
Then double click the RowUpdating Event and try pasting your code in there to see if you can get your break point to fire!
Good luck.

Resources