Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > User Server control nested in DataGrid

Reply
Thread Tools

User Server control nested in DataGrid

 
 
TokNor
Guest
Posts: n/a
 
      11-27-2003
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.Tri m();

((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
 
Reply With Quote
 
 
 
 
Michael Tkachev
Guest
Posts: n/a
 
      11-28-2003
Hi,

I foud a error in the your code.

Message.Text = ctl_lizenzart.ddl_lizenzart.SelectedItem.Value.Tri m(); -

This code is not correct.
You have to find the control in the current row.

public void LizenzListeDG_OnUpdateCommand(Object sender,
DataGridCommandEventArgs e)
{
Message.Text =
((Lizenzdialog.modules.lizenzart_liste)LizenzListe DG.Items[e.Item.ItemIndex]
..Cells[2].FindControl("ctl_lizenzart")).SelectedItem.Value. Trim();
}

This code is correct. check it.
Your answer you can to send me to my e-mail. Also if you have any questions,
you can ask me at anytime.

private.php?do=newpm&u=

bye-bye.

The Best Regards,
Web Developer
Michael Tkachev

"TokNor" <> wrote in message
news: om...
> 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.Tri m();
>
> ((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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Control to Control Other User Control Jonathan Wood ASP .Net 4 02-02-2010 03:41 PM
persisting changes to a control outside a user control from the user control? Mad Scientist Jr ASP .Net 0 03-22-2006 08:02 AM
Custom User Control is not rendered inside another user control in a server table. Leeor Chernov ASP .Net 2 10-16-2005 08:35 AM
Accessing a parent web form control from within a nested user control? Roy ASP .Net 1 02-10-2005 07:09 PM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57