Hello,
i am following this Display GridView data to RDLC Report in ASP.Net using C#.
the code work very well with id
the problem when i change the code id with Container.DataItemIndex i got error
Server Error in '/' Application.
Input string was not in a correct format.
Line 87: dsCustomers.Tables[0].Rows.Add(row.Cells[1].Text, row.Cells[2].Text, row.Cells[3].Text, row.Cells[4].Text, row.Cells[5].Text);
i am using in report viewer expression =RowNumber(Nothing)
<asp:TemplateField HeaderText="م">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
<ItemStyle Font-Size="Small" HorizontalAlign="Center" Width="30px" />
</asp:TemplateField>
<asp:BoundField DataField="name" HeaderText="إسم الموظف" SortExpression="name">
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
C# Code behind
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
string country = rblCountries.SelectedItem.Value;
string sql = "SELECT * FROM Table_infoname WHERE blockrasme=@blockrasme OR @blockrasme = '' ORDER BY [OPkdamat], [OPnqlyat] DESC";
string constr = ConfigurationManager.ConnectionStrings["kankonConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sql))
{
cmd.Parameters.AddWithValue("@blockrasme", country);
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "MouseEvents(this, event)");
e.Row.Attributes.Add("onmouseout", "MouseEvents(this, event)");
}
}
protected void btnShow1_Click(object sender, EventArgs e)
{
DataSet1 dsCustomers = new DataSet1();
foreach (GridViewRow row in GridView1.Rows)
{
if ((row.FindControl("CheckBox1") as CheckBox).Checked)
{
string id = row.Cells[1].Text;
string name = row.Cells[2].Text;
string markazel3mal = row.Cells[3].Text;
string fileid = row.Cells[4].Text;
string blockrasme = row.Cells[5].Text;
dsCustomers.Tables[0].Rows.Add(row.Cells[1].Text, row.Cells[2].Text, row.Cells[3].Text, row.Cells[4].Text, row.Cells[5].Text);
}
}
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/reportviewer/Reportfullname2.rdlc");
ReportDataSource datasource = new ReportDataSource("DataSet1", dsCustomers.Tables[0]);
ReportParameter[] param = new ReportParameter[1];
param[0] = new ReportParameter("textmsg", TextBox11.Text);
ReportViewer1.LocalReport.SetParameters(param);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}