RDLC report table not populate data from dataset - c#

I am creating an app that prints invoices through Microsoft RDLC report.The report showing some data but the tablix is not showing the values which i provide from dataset.Please see my code below and try to solve my problem.
private void InvoiceButton_Click(object sender, EventArgs e)
{
Parameters p = new Parameters();
List<Parameters> lst = new List<Parameters>();
p.date = CurrentDateTimePicker.Text;
p.CustomerName = CustomerTextBox.Text;
if (CartDataGridView.Rows.Count != 0)
{
for (int i = 0; i < CartDataGridView.Rows.Count-1; i++)
{
lst.Add(new Parameters
{
ItemName = CartDataGridView.Rows[i].Cells[1].Value.ToString(),
Price = CartDataGridView.Rows[i].Cells[2].Value.ToString(),
Quantity = CartDataGridView.Rows[i].Cells[3].Value.ToString(),
Company = CartDataGridView.Rows[i].Cells[4].Value.ToString(),
ExpiryDate = CartDataGridView.Rows[i].Cells[5].Value.ToString(),
Total = CartDataGridView.Rows[i].Cells[7].Value.ToString()
// Subtotal = (Convert.ToInt32(CartDataGridView.Rows[i].Cells[7].Value))
});
}
}
InvoiceForm f = new InvoiceForm();
ReportDataSource rd = new ReportDataSource("MyDataSet");
rd.Value = lst;
f.reportViewer1.LocalReport.ReportEmbeddedResource = "CPMSTestPhase.InvoiceReport.rdlc";
f.reportViewer1.LocalReport.DataSources.Add(rd);
ReportParameter[] rptparam = new ReportParameter[]
{
new ReportParameter("Date",p.date),
new ReportParameter("CustomerName",p.CustomerName),
// new ReportParameter("Subtotal",p.Subtotal.ToString()),
};
f.reportViewer1.LocalReport.SetParameters(rptparam);
f.reportViewer1.RefreshReport();
f.ShowDialog();
}
}ere
I try all solutions available on youtube but did not work.

I myself figured out the issue. The issue is with the order of dataset fields and my parameters class properties. They should be the same.

Related

Cardview Columns using Devexpress

created a few seconds ago
Hi,
I am creating a web page in asp.net based on data from a database. This should result in a number of tab pages with card views on each tab with 5 columns and a maximum of 20 rows. The tab pages are working, the rows are working but the columns will not change from the default 3 columns.
I have tried setting the columnCount property at different stages, post and pre databinding. This getting frustrating.
I am having problems with setting a card views column count programmatically. I am setting it, have tried to set it in different places but it always goes to the default 3 columns :(
I am using C# in Visual studio 2017.
Here is the code I am using:
SqlDataSource sds = new SqlDataSource();
public string fName;
protected void Page_Load(object sender, EventArgs e)
{
string fid = Request.QueryString["FID"];
sds.ConnectionString = ConfigurationManager.ConnectionStrings["DataBaseConnection"].ToString();
sds.SelectCommand = "select name from [flashboard] where flashboardid = " + fid;
DataView fDet = (DataView)sds.Select(DataSourceSelectArguments.Empty);
fName = fDet.Table.Rows[0]["name"].ToString();
TitleLink.InnerHtml = fName;
sds.SelectCommand = "SELECT flashboardtabid, name FROM [FlashboardTab] WHERE flashboardid = " + fid+" order by SeqNo";
DataView fTab = (DataView)sds.Select(DataSourceSelectArguments.Empty);
TabPage tabDet;
ASPxPageControl tpc = ASPxPageControl1;
ASPxCardView cardGrp;
CardViewTextColumn cName;
CardViewHyperLinkColumn cEvidence;
foreach (DataRow tab in fTab.Table.Rows)
{
tabDet = new TabPage();
tabDet.Text = tab["name"].ToString();
tabDet.Name = "Tab"+tab["flashboardtabid"].ToString();
tabDet.ActiveTabStyle.Width = Unit.Percentage( 80);
cardGrp = new ASPxCardView();
cardGrp.ID = "CardGroup" + tab["flashboardtabid"].ToString() ;
tabDet.Controls.Add(cardGrp);
tpc.TabPages.Add(tabDet);
cardGrp.AutoGenerateColumns = false;
ASPxCardViewPagerSettings cvps = new ASPxCardViewPagerSettings(cardGrp);
cardGrp.EnableTheming = true;
cardGrp.Theme = "SoftOrange";
cvps.Visible = false;
cvps.SettingsTableLayout.ColumnCount = 5;
cvps.SettingsTableLayout.RowsPerPage = 20;
cardGrp.DataSource = GetData("SELECT cardid, Description, EvidencePage, SmartViewid FROM [flashboardcard] WHERE flashboardtabid = "+tab["flashboardtabid"] + " order by SeqNo");
cardGrp.Attributes.Add("Width", "80%");
cardGrp.Attributes.Add("style", "margin:auto");
cName = new CardViewTextColumn();
cName.Name = "Description";
cName.FieldName = "Description";
cEvidence = new CardViewHyperLinkColumn();
cEvidence.Name = "EvidencePage";
cEvidence.FieldName = "EvidencePage";
cEvidence.PropertiesHyperLinkEdit.Text = "Evidence";
cardGrp.Columns.Add(cName);
cardGrp.Columns.Add(cEvidence);
var layoutitem1 = new CardViewColumnLayoutItem(); // cardGrp.CardLayoutProperties.FindColumnItem("EvidencePage");
layoutitem1.ColumnName = "EvidencePage";
layoutitem1.ShowCaption = DevExpress.Utils.DefaultBoolean.False;
layoutitem1.HorizontalAlign = FormLayoutHorizontalAlign.Center;
var layoutitem2 = new CardViewColumnLayoutItem();
layoutitem2.ColumnName = "Description";
layoutitem2.ShowCaption = DevExpress.Utils.DefaultBoolean.False;
layoutitem2.HorizontalAlign = FormLayoutHorizontalAlign.Center;
layoutitem2.ParentContainerStyle.Font.Bold = true;
layoutitem2.ParentContainerStyle.Font.Size = FontUnit.Medium;
cardGrp.CardLayoutProperties.Items.Add(layoutitem2);
cardGrp.CardLayoutProperties.Items.Add(layoutitem1);
cardGrp.DataBind();
}
}
DataView GetData(String queryString)
{
DataView ds = new DataView();
sds.SelectCommand = queryString;
ds = (DataView)sds.Select(DataSourceSelectArguments.Empty);
return ds;
}
To resolve this issue with ColumnCount, I recommend you define it directly in the control's SettingsPager.SettingsTableLayout.ColumnCount property instead of specifying it in a new ASPxCardViewPagerSettings instance:
cardGrp.SettingsPager.SettingsTableLayout.ColumnCount = 5;
cardGrp.SettingsPager.SettingsTableLayout.RowsPerPage = 20;

Reloading live charts chart only adds new data

I'm using Live Charts in my application for a pareto chart. I have made a SeriesCollection. I'm loading it from a Stored Procedure in the following way:
public void LoadChart()
{
List<DataTops> dataTops = GetTops();
ChartValues<int> Pareto = new ChartValues<int>();
List<string> timevalues = new List<string>();
int selected = ComboSelect();
IDLables = new List<string>();
foreach (var item in dataTops)
{
values.Add(item.Total);
Pareto.Add(item.Running);
IDLables.Add((item.W) + "." + (item.B));
}
TopAlarms = new SeriesCollection
{
new ColumnSeries
{
Title = "Total",
Values =values,
DataLabels = false,
ScalesYAt = 0,
},
new LineSeries
{
Title = "%",
Values = Pareto,
ScalesYAt = 1,
PointGeometrySize = 0
}
};
public List<DataTops> GetTops()
{
int selected = ComboSelect();
DataSet Ds = new DataSet();
DataSetTableAdapters.TimePerID_TopTableAdapter TimerTopta = new DataSetTableAdapters.TimePerID_TopTableAdapter();
TimerTopta.Fill(Ds.TimePerID_Top, selected);
List<DataTops> Tops = new List<DataTops>();
foreach (DataRow row in Ds.Tables["TimePerID_Top"].Rows)
{
Tops.Add(new DataTops() { Total = (int)row["Total"], W = (int)row["W"], B = (int)row["B"], Amount = (int)row["Amount"], Running = (int)row["Running"] });
}
return Tops;
}
I have a combobox to select an amount to show (selected in the dataset) and a button that I use to update the chart. The Chart works fine, but whenever I press the update button it only adds new data behind the already existing data.
Live charts doesn't automatically clear the chart collection data upon loading so I did this:
private void UpdateChart_Click(object sender, RoutedEventArgs e)
{
if (TopAlarms != null)
{
TopAlarms.Clear();
}
LoadChart();
}
But it still won't clear and reload the chart. How can i reload the chart when the button is pressed so the new selected data amount will show?
after some testing and reasearch I have the following solution for clearing the chart:
try
{
if (TopAlarms != null)
{
TopAlarms.Clear();
}
}
catch { }
This is probably not the best solution but it works for me.

Telerik report showing same data for all columns created dynamically

I have created a telerik report using Visual Studio and set the Datasource from the DataTable. I am creating the columns dynamically at runtime using Telerik.Reporting.TableGroup. Now the problem I am having here is that the report showing the same data for all of the fields and when I debug it is setting different fields for different.
The code I am using is as follows:
private void Report4_NeedDataSource(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt = SalesReport.reportDataTable;
table1.DataSource = dt;
Telerik.Reporting.HtmlTextBox textboxGroup;
Telerik.Reporting.HtmlTextBox textBoxTable;
table1.ColumnGroups.Clear();
table1.Body.Columns.Clear();
table1.Body.Rows.Clear();
int ColCount = dt.Columns.Count;
for (int i = 0; i <= ColCount - 1; i++)
{
Telerik.Reporting.TableGroup tableGroupColumn = new Telerik.Reporting.TableGroup();
table1.ColumnGroups.Add(tableGroupColumn);
textboxGroup = new Telerik.Reporting.HtmlTextBox();
textboxGroup.Style.BorderColor.Default = Color.Black;
textboxGroup.Style.BorderStyle.Default = BorderType.Solid;
textboxGroup.Value = dt.Columns[i].ColumnName;
textboxGroup.Size = new SizeU(Unit.Inch(1.5), Unit.Inch(0.6));
tableGroupColumn.ReportItem = textboxGroup;
textBoxTable = new Telerik.Reporting.HtmlTextBox();
textBoxTable.Value = "=Fields." + dt.Columns[i].ColumnName;
textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
table1.Body.SetCellContent(0, i, textBoxTable);
table1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });
}
}
I suggest reading the following article. I found this same problem and my solution was to add unique names to the group column, label, and detail text boxes.
http://www.telerik.com/forums/incorrect-dynamic-table-columns
//Added
tableGroupColumn.Name = "group" + *something_uniquegoeshere*;
//Added
textboxGroup.Name = "label" + *something_uniquegoeshere*;
//Added
textBoxTable.Name = "data" + *something_uniquegoeshere*;
Not enough space in a comment unfortunately but here's my advice/suggestion. I'm not certain about your specific error, however in the past I have had issues when re-using variables. You declare your variable outside the for statement and it is possible that this is what is causing the problem.
private void Report4_NeedDataSource(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt = SalesReport.reportDataTable;
table1.DataSource = dt;
//Telerik.Reporting.HtmlTextBox textboxGroup;
//Telerik.Reporting.HtmlTextBox textBoxTable;
table1.ColumnGroups.Clear();
table1.Body.Columns.Clear();
table1.Body.Rows.Clear();
int ColCount = dt.Columns.Count;
for (int i = 0; i <= ColCount - 1; i++)
{
Telerik.Reporting.TableGroup tableGroupColumn = new Telerik.Reporting.TableGroup();
table1.ColumnGroups.Add(tableGroupColumn);
var textboxGroup = new Telerik.Reporting.HtmlTextBox();
textboxGroup.Style.BorderColor.Default = Color.Black;
textboxGroup.Style.BorderStyle.Default = BorderType.Solid;
textboxGroup.Value = dt.Columns[i].ColumnName;
textboxGroup.Size = new SizeU(Unit.Inch(1.5), Unit.Inch(0.6));
tableGroupColumn.ReportItem = textboxGroup;
var textBoxTable = new Telerik.Reporting.HtmlTextBox();
textBoxTable.Value = "=Fields." + dt.Columns[i].ColumnName;
textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
table1.Body.SetCellContent(0, i, textBoxTable);
table1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });
}
}

Dynamic Report building Refresh() is not changing data

I am trying to View a report dynamically from code behind. But when the parameters are changed from dynamic textboxes added in the page. in the report refresh() the data is not changed.
I call sqlDS() and reportBuild() in the !IsPostback.
This method is for defining the sqlDatasource:
protected void sqlDS()
{
string conString, prName = "";
int counter = 0;
Reporting rep = new Reporting();
rep = rep.searchReport(repID_HF.Value);
Reporting repFold = new Reporting();
repFold = repFold.searchFolder(foldID_HF.Value);
if (repFold.FolderName.Split('(')[1] == "Web Reports)")
{
conString = dbSql.connectionStringAll;
prName = dbSql.providerName;
}
else
{
conString = db.connectionStringAll;
prName = db.providerName;
}
SqlDataSource1.ConnectionString = conString;
SqlDataSource1.ProviderName = prName;
string sqlString = System.IO.File.ReadAllText(Server.MapPath("~/Reports/SQLs/" + rep.SqlFile));
sqlString.Replace(System.Environment.NewLine, " ");
SqlDataSource1.SelectCommand = sqlString;
SqlDataSource1.CancelSelectOnNullParameter = false;
Reporting repParam = new Reporting();
allPs = repParam.getAllParamRep(rep.RepID);
foreach (Reporting itemParam in allPs)
{
if (itemParam.ParamType == "Date")
{
SqlDataSource1.SelectParameters.Add(":" + itemParam.ParamName, itemParam.ParamDefaultValue);
counter++;
}
else if (itemParam.ParamType == "Text")
{
SqlDataSource1.SelectParameters.Add(":" + itemParam.ParamName, itemParam.ParamDefaultValue);
counter++;
}
else if (itemParam.ParamType == "Menu")
{
counter++;
}
}
}
This method is for declaring the report properties:
protected void reportBuild()
{
Reporting rep2 = new Reporting();
rep2 = rep2.searchReport(repID_HF.Value);
ReportViewer1.LocalReport.ReportPath = "Reports/RDLC/" + rep2.RdlcFile;
this.ReportViewer1.LocalReport.ReportEmbeddedResource = rep2.RdlcFile;
ReportParameter[] paramss = new ReportParameter[SqlDataSource1.SelectParameters.Count];
for (int i = 0; i < SqlDataSource1.SelectParameters.Count; i++)
{
paramss[i] = new ReportParameter(SqlDataSource1.SelectParameters[i].Name.Split(':')[1], SqlDataSource1.SelectParameters[i].DefaultValue);
}
ReportDataSource rds = new ReportDataSource(rep2.DatasetName.Split('.')[0], SqlDataSource1);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rds);
//paramss[0] = new ReportParameter("TDATE", SqlDataSource1.SelectParameters[0].DefaultValue);
//paramss[1] = new ReportParameter("CUST_NUM", SqlDataSource1.SelectParameters[1].DefaultValue);
ReportViewer1.LocalReport.SetParameters(paramss);
ReportViewer1.LocalReport.Refresh();
}
In the reportViewer refresh method i try to set the new parameters according to the dynamic textboxes added in the page:
protected void ReportViewer1_ReportRefresh(object sender, System.ComponentModel.CancelEventArgs e)
{
foreach (Control txt in Panel1.Controls)
{
if (txt is TextBox)
{
txts.Add(txt);
}
}
foreach (TextBox txtbox in txts)
{
Reporting repP = new Reporting();
repP = repP.searchParam(txtbox.Attributes["pID"].ToString());
if (repP.ParamType == "Date")
{
SqlDataSource1.SelectParameters[":" + repP.ParamName].DefaultValue = txtbox.Text;
}
else if (repP.ParamType == "Text")
{
SqlDataSource1.SelectParameters[":" + repP.ParamName].DefaultValue = txtbox.Text;
}
}
//Reporting r = new Reporting();
//r = r.searchReport(repID_HF.Value);
//Reporting rep = new Reporting();
//rep = rep.searchReport(repID_HF.Value);
//ReportDataSource rds = new ReportDataSource(rep.DatasetName.Split('.')[0], SqlDataSource1);
//this.ReportViewer1.Reset();
//ReportViewer1.LocalReport.DataSources.Clear();
//ReportViewer1.LocalReport.DataSources.Add(rds);
ReportParameterInfoCollection x = ReportViewer1.LocalReport.GetParameters();
//Response.Redirect(Request.RawUrl);
ReportViewer1.LocalReport.Refresh();
}
I tried debugging and found every thing is working correctly the SQL parameters changed, the Report Parameters also is changed.
so why the data in the report is not changed? Plz help me
I got a better and easier way to solve this problem using this link
http://www.igregor.net/post/2007/12/Adding-Controls-to-an-ASPNET-form-Dynamically.aspx
And you can use array of strings to pass attributes.

Input data into a gridview with C#, ASP.net.

I am using a dataset that was created seperatley and is being used as a reference.
I need to create a gridview with data that comes from the dataset.
Coding is not the ASP.net code, but the C# code.
I just need to make one column of information.
Teacher has not taught us this and is on an assignment. If you can give me a link or type an example that would be great.
one way to doing is to bind the required columns with empty rows to the datatable and then binding the datatable to the girdview...i have given you a sample below
public void GenerateColumns()
{
dtblDummy = new DataTable("dtblDummy");
dtDummyColumn = new DataColumn("FirstName");
dtblDummy.Columns.Add(dtDummyColumn);
dtDummyColumn = new DataColumn("LastName");
dtblDummy.Columns.Add(dtDummyColumn);
dtDummyColumn = new DataColumn("Email");
dtblDummy.Columns.Add(dtDummyColumn);
dtDummyColumn = new DataColumn("Login");
dtblDummy.Columns.Add(dtDummyColumn);
dtDummyColumn = new DataColumn("Password");
dtblDummy.Columns.Add(dtDummyColumn);
dtDummyColumn = new DataColumn("Role");
dtblDummy.Columns.Add(dtDummyColumn);
dtDummyColumn = new DataColumn("RoleId");
dtblDummy.Columns.Add(dtDummyColumn);
}
public void GenerateRows(int intRow)
{
for(int intCounter = intRow; intCounter < intRow; intCounter++)
{
dtDummyRow = dtblDummy.NewRow();
dtDummyRow["FirstName"] = "";
dtDummyRow["LastName"] = "";
dtDummyRow["Email"] = "";
dtDummyRow["Login"] = "";
dtblDummy.Rows.Add(dtDummyRow);
}
dgrdUsers.DataSource = dtblDummy;
dgrdUsers.DataBind();
dtblDummy = null;
dtDummyRow = null;
dtDummyColumn = null;
}
in the above code dgrdUsers is the gridview control, and declare the dummy row, column and datatable above the page load function.
call the above two functions in your page load under ispostback....
dont forget the create the same no of columns as template column in your gridview...

Categories