T
TokNor
Hi all,
I am trying to create a web page where im displaying some information
in a datagrid and use a nested custom control in EditItemTemplate. In
Normal Modus it shows my Data as Label. If i go to Edit Modus it shows
me the DropDownList. That works fine and I can see the List.
If I want to Update (use the UpdateCommand) and store the Selected
Item to the Database I get an Error (System.NullReferenceException).
I have written the following code:
test.aspx
<%@ Register TagPrefix="tom" TagName="lizenzart"
Src="modules/lizenzart_liste.ascx" %>
<%@ Page language="c#" Codebehind="test2.aspx.cs"
Inherits="Lizenzdialog.Test2" Debug="true" %>
<ASPATAGRID id="LizenzListeDG" runat="server"
OnEditCommand="LizenzListeDG_OnEditCommand"
OnDeleteCommand="LizenzListeDG_OnDeleteCommand"
OnUpdateCommand="LizenzListeDG_OnUpdateCommand"
OnCancelCommand="LizenzListeDG_OnCancelCommand"
AutoGenerateColumns="False">
....
....
<asp:TemplateColumn HeaderText="LIZENZART">
<ItemTemplate>
<asp:Label runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "LIZENZART") %>'/>
</ItemTemplate>
<EditItemTemplate>
<tom:lizenzart runat="server" id="ctl_lizenzart" />
</EditItemTemplate>
</asp:TemplateColumn>
</ASPATAGRID>
test.aspx.cs
using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing;
namespace Lizenzdialog
{
public class Test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Message;
protected System.Web.UI.WebControls.DataGrid LizenzListeDG;
protected Lizenzdialog.modules.lizenzart_liste ctl_lizenzart;
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
BindData();
}
}
private void BindData()
{
LizenzData _LizenzData = new LizenzData();
DataView LizenzListeDataView = _LizenzData.GetPPNRfromPPVR("A001",
"0");
LizenzListeDG.DataSource = LizenzListeDataView;
LizenzListeDG.DataBind();
}
....
....
public void LizenzListeDG_OnUpdateCommand(Object sender,
DataGridCommandEventArgs e)
{
// Here is the Problem
Message.Text = ctl_lizenzart.ddl_lizenzart.SelectedItem.Value.Trim();
((DataGrid)sender).EditItemIndex = -1;
BindData();
}
....
}
}
lizenzart.ascx
using System;
using System.Data;
using System.Drawing;
using System.Collections;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Lizenzdialog.modules
{
public class lizenzart_liste : System.Web.UI.UserControl
{
public System.Web.UI.WebControls.DropDownList ddl_lizenzart;
private void Page_Load(object sender, System.EventArgs e)
{
BindData();
}
public void BindData()
{
ArrayList values = new ArrayList();
values.Add ("HL");
values.Add ("NL");
values.Add ("FL");
ddl_lizenzart.DataSource = values;
ddl_lizenzart.DataBind();
}
}
}
Thanks & Regards,
Tom
I am trying to create a web page where im displaying some information
in a datagrid and use a nested custom control in EditItemTemplate. In
Normal Modus it shows my Data as Label. If i go to Edit Modus it shows
me the DropDownList. That works fine and I can see the List.
If I want to Update (use the UpdateCommand) and store the Selected
Item to the Database I get an Error (System.NullReferenceException).
I have written the following code:
test.aspx
<%@ Register TagPrefix="tom" TagName="lizenzart"
Src="modules/lizenzart_liste.ascx" %>
<%@ Page language="c#" Codebehind="test2.aspx.cs"
Inherits="Lizenzdialog.Test2" Debug="true" %>
<ASPATAGRID id="LizenzListeDG" runat="server"
OnEditCommand="LizenzListeDG_OnEditCommand"
OnDeleteCommand="LizenzListeDG_OnDeleteCommand"
OnUpdateCommand="LizenzListeDG_OnUpdateCommand"
OnCancelCommand="LizenzListeDG_OnCancelCommand"
AutoGenerateColumns="False">
....
....
<asp:TemplateColumn HeaderText="LIZENZART">
<ItemTemplate>
<asp:Label runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "LIZENZART") %>'/>
</ItemTemplate>
<EditItemTemplate>
<tom:lizenzart runat="server" id="ctl_lizenzart" />
</EditItemTemplate>
</asp:TemplateColumn>
</ASPATAGRID>
test.aspx.cs
using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing;
namespace Lizenzdialog
{
public class Test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Message;
protected System.Web.UI.WebControls.DataGrid LizenzListeDG;
protected Lizenzdialog.modules.lizenzart_liste ctl_lizenzart;
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
BindData();
}
}
private void BindData()
{
LizenzData _LizenzData = new LizenzData();
DataView LizenzListeDataView = _LizenzData.GetPPNRfromPPVR("A001",
"0");
LizenzListeDG.DataSource = LizenzListeDataView;
LizenzListeDG.DataBind();
}
....
....
public void LizenzListeDG_OnUpdateCommand(Object sender,
DataGridCommandEventArgs e)
{
// Here is the Problem
Message.Text = ctl_lizenzart.ddl_lizenzart.SelectedItem.Value.Trim();
((DataGrid)sender).EditItemIndex = -1;
BindData();
}
....
}
}
lizenzart.ascx
using System;
using System.Data;
using System.Drawing;
using System.Collections;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Lizenzdialog.modules
{
public class lizenzart_liste : System.Web.UI.UserControl
{
public System.Web.UI.WebControls.DropDownList ddl_lizenzart;
private void Page_Load(object sender, System.EventArgs e)
{
BindData();
}
public void BindData()
{
ArrayList values = new ArrayList();
values.Add ("HL");
values.Add ("NL");
values.Add ("FL");
ddl_lizenzart.DataSource = values;
ddl_lizenzart.DataBind();
}
}
}
Thanks & Regards,
Tom