21. Dezember 2010 11:44
myCustomers = (CustomerPage.Customer[])GridView1.DataSource; // <---- Datasource ist immer null, obwohl Daten drin sind?
myCustomer.UpdateMultiple(ref myCustomers);
GridView1.EditIndex = -1;
GridView1.DataSource = myCustomers;
GridView1.DataBind();
3. Januar 2011 12:51
4. Januar 2011 14:33
10. Januar 2011 11:04
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
myCustomers = (CustomerPage.Customer[])GridView1.DataSource; // [b]Datasource ist immer null[/b]
myCustomer.UpdateMultiple(ref myCustomers);
GridView1.DataSource = myCustomers;
GridView1.EditIndex = -1;
GridView1.DataBind();
}
protected void Page_PreLoad(object sender, EventArgs e)
{
myGridView.DataSource = GridView1.DataSource; // myGridView ist statisch
}
10. Januar 2011 11:51
10. Januar 2011 14:46
using System;
using System.Collections;
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;
namespace OnlyGridView_Test
{
public partial class _Default : System.Web.UI.Page
{
static CustomerPage.Customer_Service myCustomer = new CustomerPage.Customer_Service();
static System.Net.NetworkCredential nc;
static GridView myGridView = new GridView();
static CustomerPage.Customer[] myCustomers;
static PlaceHolder myPlaceHolder = new PlaceHolder();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Page.PreLoad += new EventHandler(Page_PreLoad);
//Page.PreInit += new EventHandler(Page_PreInit);
//Page.PreRender += new EventHandler(Page_PreRender);
//Page.Disposed += new EventHandler(Page_Disposed);
nc = new System.Net.NetworkCredential();
nc.Domain = "cdom";
nc.UserName = "user1"; //login.userName;
nc.Password = "passwd1"; //login.userpasswd;
myCustomer.Credentials = nc;
myGridView.AutoGenerateColumns = true;
myGridView.AutoGenerateEditButton = true;
myGridView.AutoGenerateSelectButton = true;
Validate();
}
}
protected void Page_PreLoad(object sender, EventArgs e)
{
myGridView.DataSource = GridView1.DataSource;
}
protected void Customers_Click(object sender, EventArgs e)
{
myCustomers = myCustomer.ReadMultiple(null, null, 0);
GridView1.DataSource = myCustomers;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GridView1.DataSource = myCustomers;
GridView1.DataBind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
myCustomers = (CustomerPage.Customer[])GridView1.DataSource;
myCustomer.UpdateMultiple(ref myCustomers);
GridView1.DataSource = myCustomers;
GridView1.EditIndex = -1;
GridView1.DataBind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
GridView1.DataSource = myCustomers;
GridView1.DataBind();
}
}
}
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<br />
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Key"
ForeColor="#333333" GridLines="None"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
onrowcommand="GridView1_RowCommand" onrowdatabound="GridView1_RowDataBound"
onrowdeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" ShowFooter="True">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:CommandField HeaderText="Edit-Update" ShowEditButton="True" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
</Columns>
<RowStyle BackColor="#E3EAEB" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<br />
</ContentTemplate>
10. Januar 2011 14:50
10. Januar 2011 16:20
aydina81 hat geschrieben:static CustomerPage.Customer[] myCustomers;
// ...
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
myCustomers = (CustomerPage.Customer[])GridView1.DataSource; // <= ???
myCustomer.UpdateMultiple(ref myCustomers);
GridView1.DataSource = myCustomers;
GridView1.EditIndex = -1;
GridView1.DataBind();
}
10. Januar 2011 16:33
10. Januar 2011 22:45
11. Januar 2011 10:18
using System;
using System.Collections;
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;
namespace OnlyGridView_Test
{
public partial class _Default : System.Web.UI.Page
{
static CustomerPage.Customer_Service myCustomer = new CustomerPage.Customer_Service();
static System.Net.NetworkCredential nc;
static GridView myGridView = new GridView();
static CustomerPage.Customer[] myCustomers;
static PlaceHolder myPlaceHolder = new PlaceHolder();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Page.PreLoad += new EventHandler(Page_PreLoad);
//Page.PreInit += new EventHandler(Page_PreInit);
//Page.PreRender += new EventHandler(Page_PreRender);
//Page.Disposed += new EventHandler(Page_Disposed);
nc = new System.Net.NetworkCredential();
nc.Domain = "cdom";
nc.UserName = "user1"; //login.userName;
nc.Password = "passwd1"; //login.userpasswd;
myCustomer.Credentials = nc;
myGridView.AutoGenerateColumns = true;
myGridView.AutoGenerateEditButton = true;
myGridView.AutoGenerateSelectButton = true;
Validate();
}
}
protected void Page_PreLoad(object sender, EventArgs e)
{
myGridView.DataSource = GridView1.DataSource;
}
protected void Customers_Click(object sender, EventArgs e)
{
myCustomers = myCustomer.ReadMultiple(null, null, 0);
GridView1.DataSource = myCustomers;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GridView1.DataSource = myCustomers;
GridView1.DataBind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
myCustomers = (CustomerPage.Customer[])GridView1.DataSource;
myCustomer.UpdateMultiple(ref myCustomers);
GridView1.DataSource = myCustomers;
GridView1.EditIndex = -1;
GridView1.DataBind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
GridView1.DataSource = myCustomers;
GridView1.DataBind();
}
}
}
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<br />
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Key"
ForeColor="#333333" GridLines="None"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
onrowcommand="GridView1_RowCommand" onrowdatabound="GridView1_RowDataBound"
onrowdeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" ShowFooter="True">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:CommandField HeaderText="Edit-Update" ShowEditButton="True" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
</Columns>
<RowStyle BackColor="#E3EAEB" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<br />
</ContentTemplate>
12. Januar 2011 10:11
aydina81 hat geschrieben:Danke für den Tipp Kai.
12. Januar 2011 14:17