Пожалуйста, решите эту ошибку
я получаю ниже ошибку при компиляции кода.
И DataSource, и DataSourceID определены в 'GridView1'. Удалите одно определение.
Что я уже пробовал:
using System; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class viewfile : System.Web.UI.Page { private SqlConnection conn = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=college_education;User ID=sa;Password=system;"); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { gvbind(); } } protected void gvbind() { conn.Open(); SqlCommand cmd = new SqlCommand("Select * from file_rec", conn); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); conn.Close(); if (ds.Tables[0].Rows.Count > 0) { GridView1.DataSource = ds; GridView1.DataBind(); } else { ds.Tables[0].Rows.Add(ds.Tables[0].NewRow()); GridView1.DataSource = ds; GridView1.DataBind(); int columncount = GridView1.Rows[0].Cells.Count; GridView1.Rows[0].Cells.Clear(); GridView1.Rows[0].Cells.Add(new TableCell()); GridView1.Rows[0].Cells[0].ColumnSpan = columncount; GridView1.Rows[0].Cells[0].Text = "No Records Found"; } } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; Label lbldeleteid = (Label)row.FindControl("lblID"); conn.Open(); SqlCommand cmd = new SqlCommand("delete FROM file_rec where serial_no='" + Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString()) + "'", conn); cmd.ExecuteNonQuery(); conn.Close(); gvbind(); } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; gvbind(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { int serial_no = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString()); GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; Label lblID = (Label)row.FindControl("lblID"); //TextBox txtname=(TextBox)gr.cell[].control[]; TextBox textinternal_receiving = (TextBox)row.Cells[0].Controls[0]; TextBox textdate = (TextBox)row.Cells[1].Controls[0]; TextBox textdepartment = (TextBox)row.Cells[2].Controls[0]; TextBox textdepartment_type = (TextBox)row.Cells[3].Controls[0]; TextBox textorganization = (TextBox)row.Cells[4].Controls[0]; TextBox textorganization_type = (TextBox)row.Cells[5].Controls[0]; TextBox textfile_no = (TextBox)row.Cells[6].Controls[0]; TextBox textsubject = (TextBox)row.Cells[7].Controls[0]; TextBox textfile_name = (TextBox)row.Cells[8].Controls[0]; TextBox textstatus = (TextBox)row.Cells[9].Controls[0]; //TextBox textadd = (TextBox)row.FindControl("txtadd"); //TextBox textc = (TextBox)row.FindControl("txtc"); GridView1.EditIndex = -1; conn.Open(); //SqlCommand cmd = new SqlCommand("SELECT * FROM detail", conn); SqlCommand cmd = new SqlCommand("update file_rec set internal_receiving='" + textinternal_receiving + "',date='" + textdate + "',department='" + textdepartment + "',department_type='" + textdepartment_type + "',organization='" + textorganization + "',organization_type='" + textorganization_type + "',file_no='" + textfile_no + "',subject='" + textsubject + "',file_name='" + textfile_name + "',status='" + textstatus + "'where ='" + serial_no + "'", conn); cmd.ExecuteNonQuery(); conn.Close(); gvbind(); //GridView1.DataBind(); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; gvbind(); } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; gvbind(); } }