Hi Indresh,
Can U modify my code according to you...
Form.cs:
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();
}
List<DataGridViewRow> selectedRows = (from row in dataGridView1.Rows.Cast<DataGridViewRow>()
where Convert.ToBoolean(row.Cells["checkBoxColumn"].Value) == true
select row).ToList();
SampleReport sr = new SampleReport(selectedRows);
//sr.ShowDialog();
}
private void BindGrid()
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd1 = new SqlCommand("select MNO,MNAME1,MNAME1,NOMINY,ADD1,CITY,OP_DT,PHONE1,CU_SH_AMT FROM MMMEMBER",con ))
{
cmd1.CommandType = CommandType.Text;
using(SqlDataAdapter da1 = new SqlDataAdapter(cmd1))
{
using(DataTable dt1 = new DataTable())
{
da1.Fill(dt1);
dataGridView1.DataSource=dt1;
}
}
}
}
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.HeaderText = "";
checkBoxColumn.Width = 30;
checkBoxColumn.Name = "checkBoxColumn";
dataGridView1.Columns.Insert(0, checkBoxColumn);
}
RDLC Report:
public SampleReport(List<DataGridViewRow> selectedRows)
{
DataTable dt = new DataTable("DataTable1");
dt.Columns.AddRange(new DataColumn[3] {
new DataColumn("Member_No", typeof(string)), new DataColumn("Member_Name", typeof(string)), new DataColumn("Name", typeof(string)) });
foreach (DataGridViewRow row in selectedRows)
{
dt.Rows.Add(row.Cells["Member_No"].Value, row.Cells["Member_Name"].Value, row.Cells["Name"].Value);
}
WorkingMembers wm = new WorkingMembers();
wm.Merge(dt);
ReportDataSource datasource = new ReportDataSource("MMMEMBER", wm.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(datasource);
this.reportViewer1.RefreshReport();
}
private void SampleReport_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'SampleDataset.MMMEMBER' table. You can move, or remove it, as needed.
this.MMMEMBERTableAdapter.Fill(this.SampleDataset.MMMEMBER);
this.reportViewer1.RefreshReport();
}