Hi,
I have one datagrid and button(name btnview),in datagird i have checkbox in all rows,now i select(checked) the checkbox and click the button means it shows payslip for that particular employee in report viewer...if i select(checked)
more than one checkboxs means it will shows all checked(select) employee payslip but it will shows only one employee payslip i dont know reason of that....Please help me...
My c# coding..for that button..
private void btnview_Click(object sender, RoutedEventArgs e)
{
string month="";
int year=0;
DataTable dt2 = new DataTable();
string ids = string.Empty;
report r = new report();
con = new SqlConnection(cn);
con.Open();
foreach (DataRow dr in dt.Rows)
{
if (Convert.ToBoolean(dr["ischecked"]))
{
SqlCommand cmd = new SqlCommand("viewpayslip", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@pid",int.Parse(dr["p_id"].ToString()));
cmd.Parameters.AddWithValue("@month", dr["pmonth"].ToString());
cmd.Parameters.AddWithValue("@year",Int32.Parse(dr["pyear"].ToString()));
//dt2 = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt2);
//ids += dr["p_id"].ToString() + ",";
month = dr["pmonth"].ToString();
year = Int32.Parse(dr["pyear"].ToString());
}
}
r.viewpay(dt2, month,year);
r.Show();
con.Close();
//MessageBox.Show("Selected ids: " + ids.Trim(','));
}