Hallo ,
kann jemand mir hilfen bei den Code mein fehler zu finden, Vielen Dank!
using System;
using System.Configuration;
using System.Data;
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 _Default : System.Web.UI.Page
{
CustomersCls customer = new CustomersCls();
protected void Page_Load(object sender, EventArgs e)
{
If(!IsPostBack);
{
FillCustomerInGrid();
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
private void FillCustomerInGrid()
{
DataTable dtCustomer= customer.Fetch();
if (dtCustomer.Rows.Count>0)
{
GridView1.DataSource = dtCustomer;
GridView1.DataBind();
}
else
{
dtCustomer.Rows.Add(dtCustomer.NewRow());
GridView1.DataSource = dtCustomer;
GridView1.DataBind();
int TotalColumns = GridView1.Rows[0].Cells.Count;
GridView1.Rows[0].Cells.Clear();
GridView1.Rows[0].Cells.Add(new TableCell());
GridView1.Rows[0].Cells[0].ColumnSpan = TotalColumns;
GridView1.Rows[0].Cells[0].Text = "No Record Found";
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList cmbType = (DropDownList)e.Row.FindControl("cmbType");
if (cmbType != null)
{
cmbType.DataSource = customer.FetchCustomerType();
cmbType.DataBind();
cmbType.SelectedValue = GridView1.DataKeys[e.Row.RowIndex].Values[1].ToString();
}
}
if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList cmbNewType = (DropDownList)e.Row.FindControl("cmbNewType");
cmbNewType.DataSource = customer.FetchCustomerType();
cmbNewType.DataBind();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew"))
{
TextBox txtNewName = (TextBox)GridView1.FooterRow.FindControl("txtNewNa me");
DropDownList cmbNewGender = (DropDownList)GridView1.FooterRow.FindControl("cmb NewGender");
TextBox txtNewCity = (TextBox)GridView1.FooterRow.FindControl("txtNewCi ty");
TextBox txtNewState = (TextBox)GridView1.FooterRow.FindControl("txtNewSt ate");
DropDownList cmbNewType = (DropDownList)GridView1.FooterRow.FindControl("cmb NewType");
customer.Insert(txtNewName.Text, cmbNewGender.SelectedValue, txtNewCity.Text, txtNewState.Text, cmbNewType.SelectedValue);
FillCustomerInGrid();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
cmbType.SelectedValue = GridView1.DataKeys[e.Row.RowIndex].Values[1].ToString();
GridView1.EditIndex = e.NewEditIndex;
FillCustomerInGrid();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
FillCustomerInGrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtName");
DropDownList cmbGender = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("cmbGender");
TextBox txtCity = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCity");
DropDownList cmbType = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("cmbType");
customer.Update(GridView1.DataKeys[e.RowIndex].Values[0].ToString(), txtName.Text, cmbGender.SelectedValue, txtCity.Text, CustomerType.SelectedValue);
GridView1.EditIndex = -1;
FillCustomerInGrid();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
customer.Delete(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
FillCustomerInGrid();
}
}
kann jemand mir hilfen bei den Code mein fehler zu finden, Vielen Dank!
using System;
using System.Configuration;
using System.Data;
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 _Default : System.Web.UI.Page
{
CustomersCls customer = new CustomersCls();
protected void Page_Load(object sender, EventArgs e)
{
If(!IsPostBack);
{
FillCustomerInGrid();
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
private void FillCustomerInGrid()
{
DataTable dtCustomer= customer.Fetch();
if (dtCustomer.Rows.Count>0)
{
GridView1.DataSource = dtCustomer;
GridView1.DataBind();
}
else
{
dtCustomer.Rows.Add(dtCustomer.NewRow());
GridView1.DataSource = dtCustomer;
GridView1.DataBind();
int TotalColumns = GridView1.Rows[0].Cells.Count;
GridView1.Rows[0].Cells.Clear();
GridView1.Rows[0].Cells.Add(new TableCell());
GridView1.Rows[0].Cells[0].ColumnSpan = TotalColumns;
GridView1.Rows[0].Cells[0].Text = "No Record Found";
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList cmbType = (DropDownList)e.Row.FindControl("cmbType");
if (cmbType != null)
{
cmbType.DataSource = customer.FetchCustomerType();
cmbType.DataBind();
cmbType.SelectedValue = GridView1.DataKeys[e.Row.RowIndex].Values[1].ToString();
}
}
if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList cmbNewType = (DropDownList)e.Row.FindControl("cmbNewType");
cmbNewType.DataSource = customer.FetchCustomerType();
cmbNewType.DataBind();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew"))
{
TextBox txtNewName = (TextBox)GridView1.FooterRow.FindControl("txtNewNa me");
DropDownList cmbNewGender = (DropDownList)GridView1.FooterRow.FindControl("cmb NewGender");
TextBox txtNewCity = (TextBox)GridView1.FooterRow.FindControl("txtNewCi ty");
TextBox txtNewState = (TextBox)GridView1.FooterRow.FindControl("txtNewSt ate");
DropDownList cmbNewType = (DropDownList)GridView1.FooterRow.FindControl("cmb NewType");
customer.Insert(txtNewName.Text, cmbNewGender.SelectedValue, txtNewCity.Text, txtNewState.Text, cmbNewType.SelectedValue);
FillCustomerInGrid();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
cmbType.SelectedValue = GridView1.DataKeys[e.Row.RowIndex].Values[1].ToString();
GridView1.EditIndex = e.NewEditIndex;
FillCustomerInGrid();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
FillCustomerInGrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtName");
DropDownList cmbGender = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("cmbGender");
TextBox txtCity = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCity");
DropDownList cmbType = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("cmbType");
customer.Update(GridView1.DataKeys[e.RowIndex].Values[0].ToString(), txtName.Text, cmbGender.SelectedValue, txtCity.Text, CustomerType.SelectedValue);
GridView1.EditIndex = -1;
FillCustomerInGrid();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
customer.Delete(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
FillCustomerInGrid();
}
}
Comment