Madan Kumar

Madan Kumar

  • NA
  • 6
  • 535

I am unable to get the file inside the gridview with upload

Aug 31 2016 1:43 AM
int index = int.Parse(((Button)sender).CommandArgument);
BLL.Masters _objBll = new BLL.Masters();
var dir = @"D:\\madan\\30-08-2016\\MK_Alumni_Web\\MK_Alumni_Web\Resources\\Images\\" + CtrlTxtStudentID.Text;
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
foreach (HttpPostedFile postedFile in FileUpload2.PostedFiles)
{
string fileName = Path.GetFileName(postedFile.FileName);
postedFile.SaveAs(Path.Combine(dir, fileName));
}
try
{
int std_id = Convert.ToInt32(CtrlTxtStudentID.Text);
bool result = false;
DataRow dr;
DataRow dr1;
DataRow dr2;
DataRow dr3;
DataTable dt2 = new DataTable();
DataTable dt1 = new DataTable();
DataTable dt = new DataTable();
dt1 = objBus.fillDataTable("select * from Contact_Master where 1=0", CommandType.Text);
dt2 = objBus.fillDataTable("select * from Profile where 1=0", CommandType.Text);
dt = objBus.fillDataTable("select * from Std_Master where 1=0", CommandType.Text);
dr = dt.NewRow();
dr1 = dt1.NewRow();
dr2 = dt1.NewRow();
dr3 = dt2.NewRow();
dr["Std_No"] = CtrlTxtStudentID.Text != "" ? Convert.ToString(CtrlTxtStudentID.Text) : "";
dr["Std_FullName"] = CtrlTxtStudentID.Text != "" ? Convert.ToString(CtrlTxtStudentID.Text) : "";
dr["Std_knownName"] = CtrlTxtStudentID.Text != "" ? Convert.ToString(CtrlTxtStudentID.Text) : "";
dr["Batch_ID"] = CtrlCombobatch.SelectedValue != "" ? Convert.ToInt32(CtrlCombobatch.SelectedValue) : 0;
dr["Std_PassedOutDate"] = Convert.ToDateTime(CtrlTxtPassedOutDate.Text);
dr["Std_PassedOutYear"] = DateTime.Now;
dr["Std_Gender"] = ddlGender.Text != "" ? Convert.ToString(ddlGender.Text) : "";
dr["Std_FatherName"] = CtrlTxtFatherName.Text != "" ? Convert.ToString(CtrlTxtFatherName.Text) : "";
dr["Std_MotherName"] = CtrlTxtmotherName.Text != "" ? Convert.ToString(CtrlTxtmotherName.Text) : "";
dr["Std_MaritialStatus"] = ddlmaritial.SelectedValue != "" ? Convert.ToInt32(ddlmaritial.SelectedValue) : 0;
dr["Std_SpouseName"] = CtrlTxtSpouseName.Text != "" ? Convert.ToString(CtrlTxtSpouseName.Text) : "";
dr["Std_MarriageDate"] = Convert.ToDateTime(CtrlTxtMrgDate.Text);
dr["Std_DOB"] = Convert.ToDateTime(CtrlTxtDOb.Text);
dr["Std_Status"] = CtrlComboStatus.SelectedValue != "" ? Convert.ToInt32(CtrlComboStatus.SelectedValue) : 0;
dr["CB"] = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
dr["CB"] = DateTime.Now;
foreach (GridViewRow row in gvAddRow.Rows)
{
DropDownList drpacademic = (DropDownList)row.FindControl("ddlCity");
TextBox Cnt_Address = (TextBox)row.FindControl("Cnt_Address");
TextBox Cnt_Remarks = (TextBox)row.FindControl("Cnt_Remarks");
TextBox Cnt_City = (TextBox)row.FindControl("Cnt_City");
TextBox Cnt_Pincode = (TextBox)row.FindControl("Cnt_Pincode");
TextBox Cnt_State = (TextBox)row.FindControl("Cnt_State");
TextBox Cnt_Country = (TextBox)row.FindControl("Cnt_Country");
TextBox Cnt_PhoneNumber = (TextBox)row.FindControl("Cnt_PhoneNumber");
TextBox Cnt_Email = (TextBox)row.FindControl("Cnt_Email");
dr1 = dt1.NewRow();
dr1["CntType_ID"] = Convert.ToInt32(drpacademic.SelectedValue);
dr1["Cnt_Address"] = Cnt_Address.Text != "" ? Convert.ToString(Cnt_Address.Text) : "";
dr1["Cnt_Remarks"] = Cnt_Remarks.Text != "" ? Convert.ToString(Cnt_Remarks.Text) : "";
dr1["Cnt_City"] = Cnt_City.Text != "" ? Convert.ToString(Cnt_City.Text) : "";
dr1["Cnt_Pincode"] = Cnt_Pincode.Text != "" ? Convert.ToString(Cnt_Pincode.Text) : "";
dr1["Cnt_State"] = Cnt_State.Text != "" ? Convert.ToString(Cnt_State.Text) : "";
dr1["Cnt_Country"] = Cnt_Country.Text != "" ? Convert.ToString(Cnt_Country.Text) : "";
dr1["Cnt_PhoneNumber"] = Cnt_PhoneNumber.Text != "" ? Convert.ToString(Cnt_PhoneNumber.Text) : "";
dr1["Cnt_Email"] = Cnt_Email.Text != "" ? Convert.ToString(Cnt_Email.Text) : "";
dr1["CB"] = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
dr1["CB"] = DateTime.Now;
dt1.Rows.Add(dr1);
}
foreach (GridViewRow row in GridView1.Rows)
{
DropDownList drpacademic = (DropDownList)row.FindControl("ddlProType");
TextBox Pro_title = (TextBox)row.FindControl("Pro_title");
TextBox Pro_Desc = (TextBox)row.FindControl("Pro_Desc");
TextBox CtrlTxtProDate = (TextBox)row.FindControl("CtrlTxtProDate");
TextBox CtrlTxtPro_FromDate = (TextBox)row.FindControl("CtrlTxtPro_FromDate");
TextBox CtrlTxtProToDate = (TextBox)row.FindControl("CtrlTxtProToDate");
TextBox Pro_Dept = (TextBox)row.FindControl("Pro_Dept");
TextBox Pro_Designation = (TextBox)row.FindControl("Pro_Designation");
TextBox Pro_Authority = (TextBox)row.FindControl("Pro_Authority");
TextBox Pro_City = (TextBox)row.FindControl("Pro_City");
TextBox Pro_Role = (TextBox)row.FindControl("Pro_Role");
FileUpload file = (FileUpload)GridView1.Rows[index].FindControl("FileUpload3");
{
if (file != null)
{
if (file.HasFile)
{
var dir1 = @"D:\\madan\\30-08-2016\\MK_Alumni_Web\\MK_Alumni_Web\Resources\\Images\\" + CtrlTxtStudentID.Text;
if (!Directory.Exists(dir1))
Directory.CreateDirectory(dir1);
foreach (HttpPostedFile postedFile in file.PostedFiles)
{
string fileName = Path.GetFileName(postedFile.FileName);
postedFile.SaveAs(Path.Combine(dir1, fileName));
}
}
}
}
dr2 = dt2.NewRow();
dr2["ProType_ID"] = Convert.ToInt32(drpacademic.SelectedValue);
dr2["Pro_title"] = Pro_title.Text != "" ? Convert.ToString(Pro_title.Text) : "";
dr2["Pro_Date"] = Convert.ToDateTime(CtrlTxtProDate.Text != "" ? Convert.ToString(CtrlTxtProDate.Text) : "");
dr2["Pro_FromDate"] = Convert.ToDateTime(CtrlTxtPro_FromDate.Text != "" ? Convert.ToString(CtrlTxtPro_FromDate.Text) : "");
dr2["Pro_ToDate"] = Convert.ToDateTime(CtrlTxtProToDate.Text != "" ? Convert.ToString(CtrlTxtProToDate.Text) : "");
dr2["Pro_Dept"] = Pro_Dept.Text != "" ? Convert.ToString(Pro_Dept.Text) : "";
dr2["Pro_Designation"] = Pro_Designation.Text != "" ? Convert.ToString(Pro_Designation.Text) : "";
dr2["Pro_Authority"] = Pro_Authority.Text != "" ? Convert.ToString(Pro_Authority.Text) : "";
dr2["Pro_City"] = Pro_City.Text != "" ? Convert.ToString(Pro_City.Text) : "";
dr2["Pro_Role"] = Pro_Role.Text != "" ? Convert.ToString(Pro_Role.Text) : "";
dr2["CB"] = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
dr2["CB"] = DateTime.Now;
dt2.Rows.Add(dr2);
dt2.AcceptChanges();
}
dt.Rows.Add(dr);
if (dt.Rows.Count > 0)
{
result = _objBll.SavestudentDetails(dt, dt1, dt2);
if (result == true)
{
//Clear();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Notify", "alert('Student created sucessfully !');", true);
// btnAdd.Visible = false;
Panel_DisplayStudentDetail.Visible = true;
Fill_student_Details();
}
}