Design
Update FIR
Code Behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace Final_Project
{
public partial class Update_FIR : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=AHZAM-PC\\AHZAM;Initial Catalog=Police;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) // If you not place this check then you will get the old values because GridView in Bind on every postback
{
DataBind();
}
}
private void BindGrid() // function for binding gridview
{
DataTable dt = new DataTable();
dt.Columns.Add("FIR_ID");
dt.Columns.Add("Police_ID");
dt.Columns.Add("Victim_FullName");
dt.Columns.Add("Date");
dt.Columns.Add("District");
dt.Columns.Add("PoliceStation");
dt.Columns.Add("Act");
dt.Columns.Add("Section");
dt.Columns.Add("Occurence Address");
DataRow r = dt.NewRow();
r[0] = "FIR_ID 1";
r[1] = "Police_ID 1";
r[2] = "Victim_FullName 1";
r[3] = "Date 1";
r[4] = "District 1";
r[5] = "PoliceStation 1";
r[6] = "Act 1";
r[7] = "Sections 1";
r[8] = "Occurence Address 1";
DataRow r1 = dt.NewRow();
r1[0] = "FIR_ID 2";
r1[1] = "Police_ID 2";
r1[2] = "Victim_FullName 2";
r1[3] = "Date 2";
r1[4] = "District 2";
r1[5] = "PoliceStation 2";
r1[6] = "Act 2";
r1[7] = "Sections 2";
r1[8] = "Occurence Address 2";
dt.Rows.Add(r);
dt.Rows.Add(r1);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex; // setting new index
BindGrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
string newvalue = ((TextBox)row.Cells[0].Controls[0]).Text;
GridView1.EditIndex = -1; // Again reset
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1; // reseting grid view
BindGrid();
}
}
}
After Execution the browser only display the heading and no Grid view at all. help please.
Rajeesh MenothPosted Jul 29, 2015, 1:55 AM
Occurence_Address
Rajeesh MenothPosted Jul 29, 2015, 1:46 AM
Upendra Pratap ShahiPosted Jul 29, 2015, 1:34 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace Final_Project
{
public partial class Update_FIR : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=AHZAM-PC\\AHZAM;Initial Catalog=Police;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) // If you not place this check then you will get the old values because GridView in Bind on every postback
{
//DataBind();
BindGrid();
}
}
private void BindGrid() // function for binding gridview
{
DataTable dt = new DataTable();
dt.Columns.Add("FIR_ID");
dt.Columns.Add("Police_ID");
dt.Columns.Add("Victim_FullName");
dt.Columns.Add("Date");
dt.Columns.Add("District");
dt.Columns.Add("PoliceStation");
dt.Columns.Add("Act");
dt.Columns.Add("Section");
dt.Columns.Add("Occurence Address");
DataRow r = dt.NewRow();
r[0] = "FIR_ID 1";
r[1] = "Police_ID 1";
r[2] = "Victim_FullName 1";
r[3] = "Date 1";
r[4] = "District 1";
r[5] = "PoliceStation 1";
r[6] = "Act 1";
r[7] = "Sections 1";
r[8] = "Occurence Address 1";
DataRow r1 = dt.NewRow();
r1[0] = "FIR_ID 2";
r1[1] = "Police_ID 2";
r1[2] = "Victim_FullName 2";
r1[3] = "Date 2";
r1[4] = "District 2";
r1[5] = "PoliceStation 2";
r1[6] = "Act 2";
r1[7] = "Sections 2";
r1[8] = "Occurence Address 2";
dt.Rows.Add(r);
dt.Rows.Add(r1);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex; // setting new index
BindGrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
string newvalue = ((TextBox)row.Cells[0].Controls[0]).Text;
GridView1.EditIndex = -1; // Again reset
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1; // reseting grid view
BindGrid();
}
}
}
Rajeesh MenothPosted Jul 29, 2015, 2:44 AM
Upendra Pratap ShahiPosted Jul 29, 2015, 2:11 AM
Azm AmnPosted Jul 29, 2015, 2:07 AM
Azm AmnPosted Jul 29, 2015, 1:51 AM
A field or property with the name 'Occurence_Address' was not found on the selected data source.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Web.HttpException: A field or property with the name 'Occurence_Address' was not found on the selected data source.
Source Error:
Upendra Pratap ShahiPosted Jul 29, 2015, 1:46 AM
Azm AmnPosted Jul 29, 2015, 1:45 AM
Azm AmnPosted Jul 29, 2015, 1:43 AM
Azm AmnPosted Jul 29, 2015, 1:42 AM
Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.InvalidOperationException: Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.
Rajeesh MenothPosted Jul 29, 2015, 1:42 AM
Vignesh ManiPosted Jul 29, 2015, 1:22 AM