When i click on the select button all other fields are populated with data except the fileupload button
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.Expressions;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.IO;
using LMCSS.P;
namespace Langkuk_Memorial_Sech.School.pages.setup
{
public partial class istudent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.AutoGenerateSelectButton = true;
GridView1.AutoGenerateDeleteButton = false;
GridView1.PageSize = 4;
showdata();
}
public void showdata()
{
string cs = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
OleDbConnection conn = new OleDbConnection(cs);
conn.Open();
OleDbDataAdapter adap = new OleDbDataAdapter("stuSelectAll", conn);
adap.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
adap.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
conn.Close();
}
public void btnReset_Click(object sender, ImageClickEventArgs e)
{
txtRegno.Text = "";
txtSurname.Text = "";
txtOthernames.Text = "";
txtDOB.Text = "";
txtPhoneno.Text = "";
txtContactaddress.Text = "";
txtEmail.Text = "";
mbox1.Visible = false;
}
protected void btnSave_Click(object sender, ImageClickEventArgs e)
{
int imagelength = FileUpload1.PostedFile.ContentLength;
byte[] imagebyte = new byte[imagelength];
FileUpload1.PostedFile.InputStream.Read(imagebyte, 0, imagelength);
string cs = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
OleDbConnection conn = new OleDbConnection(cs);
conn.Open();
OleDbCommand cmd = new OleDbCommand("stuInsert", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@regno", txtRegno.Text);
cmd.Parameters.AddWithValue("@surname", txtSurname.Text);
cmd.Parameters.AddWithValue("@othernames", txtOthernames.Text);
cmd.Parameters.AddWithValue("@dob", txtDOB.Text);
cmd.Parameters.AddWithValue("@genderid", ddlGender.SelectedValue);
cmd.Parameters.AddWithValue("@religionid", ddlReligion.SelectedValue);
cmd.Parameters.AddWithValue("@nationalityid", ddlNationlity.SelectedValue);
cmd.Parameters.AddWithValue("@stateid", ddlState.SelectedValue);
cmd.Parameters.AddWithValue("@lgaid", ddlLga.SelectedValue);
cmd.Parameters.AddWithValue("@phonenumber", txtPhoneno.Text);
cmd.Parameters.AddWithValue("@contactaddress", txtContactaddress.Text);
cmd.Parameters.AddWithValue("@email", txtEmail.Text);
cmd.Parameters.AddWithValue("@classid", ddlClass.SelectedValue);
cmd.Parameters.AddWithValue("@picture", imagebyte);
int result = cmd.ExecuteNonQuery();
if(result>0)
{
btnReset_Click(sender, e);
mbox1.showmsg(1, "student saved successfully");
}
else
{
btnReset_Click(sender, e);
mbox1.showmsg(3, "student not-saved successfully");
}
conn.Close();
showdata();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
showdata();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
{
txtID.Text = GridView1.SelectedRow.Cells[2].Text;
txtRegno.Text = GridView1.SelectedRow.Cells[3].Text;
txtSurname.Text = GridView1.SelectedRow.Cells[4].Text;
txtOthernames.Text = GridView1.SelectedRow.Cells[5].Text;
txtDOB.Text = GridView1.SelectedRow.Cells[6].Text;
ddlGender.Text = GridView1.SelectedRow.Cells[7].Text.ToString();
ddlReligion.Text = GridView1.SelectedRow.Cells[8].Text.ToString();
ddlNationlity.Text = GridView1.SelectedRow.Cells[9].Text.ToString();
ddlState.Text = GridView1.SelectedRow.Cells[10].Text.ToString();
ddlLga.Text = GridView1.SelectedRow.Cells[11].Text.ToString();
txtPhoneno.Text = GridView1.SelectedRow.Cells[12].Text;
txtContactaddress.Text = GridView1.SelectedRow.Cells[13].Text;
txtEmail.Text = GridView1.SelectedRow.Cells[14].Text;
ddlClass.Text = GridView1.SelectedRow.Cells[15].Text.ToString();
}
protected void btnUPdate_Click(object sender, ImageClickEventArgs e)
{
int imagelength = FileUpload1.PostedFile.ContentLength;
byte[] imagebyte = new byte[imagelength];
FileUpload1.PostedFile.InputStream.Read(imagebyte, 0, imagelength);
string cs = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
OleDbConnection conn = new OleDbConnection(cs);
conn.Open();
OleDbCommand cmd = new OleDbCommand("stuUpdate", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", txtID.Text.ToString());
cmd.Parameters.AddWithValue("@regno", txtRegno.Text);
cmd.Parameters.AddWithValue("@surname", txtSurname.Text);
cmd.Parameters.AddWithValue("@othernames", txtOthernames.Text);
cmd.Parameters.AddWithValue("@dob", txtDOB.Text);
cmd.Parameters.AddWithValue("@genderid", ddlGender.SelectedValue);
cmd.Parameters.AddWithValue("@religionid", ddlReligion.SelectedValue);
cmd.Parameters.AddWithValue("@nationalityid", ddlNationlity.SelectedValue);
cmd.Parameters.AddWithValue("@stateid", ddlState.SelectedValue);
cmd.Parameters.AddWithValue("@lgaid", ddlLga.SelectedValue);
cmd.Parameters.AddWithValue("@phonenumber", txtPhoneno.Text);
cmd.Parameters.AddWithValue("@contactaddress", txtContactaddress.Text);
cmd.Parameters.AddWithValue("@email", txtEmail.Text);
cmd.Parameters.AddWithValue("@classid", ddlClass.SelectedValue);
cmd.Parameters.AddWithValue("@picture", imagebyte);
int result = cmd.ExecuteNonQuery();
if (result > 0)
{
btnReset_Click(sender, e);
mbox1.showmsg(1, "student updated successfully");
}
else
{
btnReset_Click(sender, e);
mbox1.showmsg(3, "student not-updated successfully");
}
conn.Close();
showdata();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
}
protected void btnDelete_Click(object sender, ImageClickEventArgs e)
{
int imagelength = FileUpload1.PostedFile.ContentLength;
byte[] imagebyte = new byte[imagelength];
FileUpload1.PostedFile.InputStream.Read(imagebyte, 0, imagelength);
string cs = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
OleDbConnection conn = new OleDbConnection(cs);
conn.Open();
OleDbCommand cmd = new OleDbCommand("stuDelete", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", txtID.Text.ToString());
int result = Convert.ToInt32(cmd.ExecuteNonQuery().ToString());
if (result > 0)
{
mbox1.showmsg(1, "student deleted successfully");
}
else
{
mbox1.showmsg(3, "student not-deleted successfully");
}
conn.Close();
}
}
}