Hemal Joshi

Hemal Joshi

  • NA
  • 78
  • 47.1k

Selected Data from DataGridView display in RDLC Report

Jan 20 2018 2:29 AM
Hello,
 
I am generating one form where i have two text boxes, two labels, and button Show now when i enter values in both text box and click on Show button data is displayed in dataGridView now when i want to click Generate Button it will only display selected data from dataGridView to the RDLC report viewer help me for that.
 
Run Time: 
 
Report: 
 
Code: 
private void btnShow_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(textBox1.Text.Trim()))
{
MessageBox.Show("Plese Enter Value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from MMMEMBER where MNO between " + Convert.ToInt32(textBox1.Text.Trim()) + " and " + Convert.ToInt32(textBox2.Text.Trim()), con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.ColumnCount = 9;
//Add Columns
dataGridView1.Columns[0].Name = "MNO";
dataGridView1.Columns[0].HeaderText = "MNO";
dataGridView1.Columns[0].DataPropertyName = "MNO";
dataGridView1.Columns[1].Name = "MNAME";
dataGridView1.Columns[1].HeaderText = "MNAME";
dataGridView1.Columns[1].DataPropertyName = "MNAME";
dataGridView1.Columns[2].Name = "MNAME1";
dataGridView1.Columns[2].HeaderText = "MNAME1";
dataGridView1.Columns[2].DataPropertyName = "MNAME1";
dataGridView1.Columns[3].Name = "NOMINY";
dataGridView1.Columns[3].HeaderText = "NOMINY";
dataGridView1.Columns[3].DataPropertyName = "NOMINY";
dataGridView1.Columns[4].Name = "ADD1";
dataGridView1.Columns[4].HeaderText = "ADD1";
dataGridView1.Columns[4].DataPropertyName = "ADD1";
dataGridView1.Columns[5].Name = "CITY";
dataGridView1.Columns[5].HeaderText = "CITY";
dataGridView1.Columns[5].DataPropertyName = "CITY";
dataGridView1.Columns[6].Name = "OP_DT";
dataGridView1.Columns[6].HeaderText = "OP_DT";
dataGridView1.Columns[6].DataPropertyName = "OP_DT";
dataGridView1.Columns[7].Name = "PHONE1";
dataGridView1.Columns[7].HeaderText = "PHONE1";
dataGridView1.Columns[7].DataPropertyName = "PHONE1";
dataGridView1.Columns[8].Name = "CU_SH_AMT";
dataGridView1.Columns[8].HeaderText = "CU_SH_AMT";
dataGridView1.Columns[8].DataPropertyName = "CU_SH_AMT";
dataGridView1.DataSource = dt;
con.Close();
}
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.HeaderText = "";
checkBoxColumn.Width = 30;
checkBoxColumn.Name = "checkBoxColumn";
dataGridView1.Columns.Insert(0, checkBoxColumn);
List selectedRows = (from row in dataGridView1.Rows.Cast()
where Convert.ToBoolean(row.Cells["checkBoxColumn"].Value) == true
select row).ToList();
SampleReport sr = new SampleReport(selectedRows);
//sr.ShowDialog();
}
private void btnGenerate_Click(object sender, EventArgs e)
{
new SampleReport().Show();
}
 
Thanks 

Answers (9)