473,837 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Events in DataList EditItem Template won't fire

Hi all,

I am developing an asp.net 2.0 application in Visual Studio 2005. On
my page I have a simple datalist that is bound programmaticall y to a
collection of simple objects. On this page I need to control the
visibility of a textbox based on a dropdown selection in the
datalist's edititem template. To do this, I registered a client script
block function and attached a client side handler for the
dropdownlist's onchange event in the datalist's OnItemCreated event.
The client script works fine, but I find that the update and cancel
events won't fire in the EditItem template. My edit, delete, and add
event fire fine in the ItemTemplate. I also find that if I remove the
client side onchange event handler the EditItem commands work fine.
Here is the code --
protected void Page_Load(objec t sender, EventArgs e)
{
// Register client script block containing the event handler for the
datalist's dropdownlist control.
ClientScriptMan ager csm = this.ClientScri pt;
string script = "function EnableCheckNumb erVisibility(Ty pe,
CheckNumber)\n" +
"{ \n" +
"if (Type.value == 'K') { \n" +
"CheckNumber.st yle.visibility = 'visible'; \n"
+
"} else {\n" +
"CheckNumber.st yle.visibility = 'hidden';\n" +
"}\n" +
"return true;\n" +
"}";
csm.RegisterCli entScriptBlock( this.GetType(),
"EnableCheckNum berVisibility", script,true);
if (!IsPostBack)
{
// Get Custom object collection out of session
Payments = BLL.Payments.ge tPaymentsByMemb erId("XXXXXX");
txtMemberAmount .Text =
Payments.Member Amount.ToString ("c");
txtDependentAmo unt.Text =
Payments.Depend entAmount.ToStr ing("c");
txtLateFee.Text = Payments.LateFe e.ToString("c") ;
txtAdminFee.Tex t = Payments.AdminF ee.ToString("c" );
txtTotalDues.Te xt = Payments.TotalD ues.ToString("c ");

Payments.Paymen tCollection.Add (new BLL.Payment());

PaymentTypes = BLL.Payment.get PaymentTypes();

dlPayments.Data Source = Payments.Paymen tCollection;
dlPayments.Data Bind();
}
}
protected void dlPayments_Item Command(object sender,
DataListCommand EventArgs e)
{
DataList dl = (DataList)sende r;

switch (e.CommandName)
{
case "add":
Payments.add(ne w BLL.Payment());

dlPayments.Data Source = Payments.Paymen tCollection;
dlPayments.Data Bind();
break;
}

}
protected void dlPayments_Item DataBound(objec t sender,
DataListItemEve ntArgs e)
{
if ((e.Item.ItemTy pe == ListItemType.It em) ||
(e.Item.ItemTyp e == ListItemType.Se lectedItem) ||
(e.Item.ItemTyp e == ListItemType.Al ternatingItem)
)
{
BLL.Payment p = (BLL.Payment)e. Item.DataItem;
foreach (ListItem i in PaymentTypes)
{
if (i.Value == p.TypeCode)
{
Label l =
(Label)e.Item.F indControl("lbl PaymentType");
l.Text = i.Text;
break;
}
}
}
}
protected void dlPayments_Item Created(object sender,
DataListItemEve ntArgs e)
{
// hook up the event handler here
if (e.Item.ItemTyp e == ListItemType.Ed itItem)
{
DropDownList dl =
(DropDownList)e .Item.FindContr ol("ddlType");

dl.Items.AddRan ge(PaymentTypes .ToArray());

TextBox tb =
(TextBox)e.Item .FindControl("t xtCheckNumber") ;

dl.Attributes["onchange"] = "EnableCheckNum berVisibility("
+ dl.ClientID + "," +
tb.ClientID + ");";

}
}
protected void dlPayments_Dele teCommand(objec t source,
DataListCommand EventArgs e)
{
if (e.Item.ItemInd ex 0)
{

Payments.remove (Payments.Payme ntCollection[e.Item.ItemInde x]);
((DataList)sour ce).DataSource =
Payments.Paymen tCollection;
dlPayments.Data Bind();
}

}
protected void dlPayments_Edit Command(object source,
DataListCommand EventArgs e)
{
((DataList)sour ce).EditItemInd ex = e.Item.ItemInde x;
((DataList)sour ce).DataSource = Payments.Paymen tCollection;
((DataList)sour ce).DataBind();
}
protected void dlPayments_Upda teCommand(objec t source,
DataListCommand EventArgs e)
{
DataList dl = (DataList)sourc e;

// Payment Type
DropDownList ddlType =
(DropDownList)e .Item.FindContr ol("ddlType");
Payments.Paymen tCollection[e.Item.ItemInde x].TypeCode =
ddlType.Selecte dValue;

// Amount
TextBox txtAmount = (TextBox)e.Item .FindControl("t xtAmount");
Payments.Paymen tCollection[e.Item.ItemInde x].Amount =
Single.Parse(tx tAmount.Text);

// Check Number
TextBox txtCheckNumber =
(TextBox)e.Item .FindControl("t xtCheckNumber") ;
Payments.Paymen tCollection[e.Item.ItemInde x].CheckNumber =
txtCheckNumber. Text;

dl.DataSource = Payments.Paymen tCollection;
dl.EditItemInde x = -1;
dl.DataBind();

}
protected void dlPayments_Canc elCommand(objec t source,
DataListCommand EventArgs e)
{
DataList dl = (DataList)sourc e;

dl.DataSource = Payments.Paymen tCollection;
dl.EditItemInde x = -1;
dl.DataBind();
}
Oct 13 '08 #1
3 2814
The first thing I am going to suggest is that you use a
System.Text.Str ingBuilder to create the JavaScript rather than a bunch of
concatenation operators (it is more efficient and the code is easier to
read). In your EnableCheckNumb erVisibility function, what is CheckNumber? If
it is one of the controls, it will not work because the ID used on the
client is not the one you enter server-side (you need to use the ClientId
property to get the generated ID, do a View Source in your browser to see
what I'm talking about). Also, when referencing an element in JavaScript,
you should always use the document.getEle mentById(elemen tid) method. Also, I
think it would be helpful to everyone in these newsgroups if you posted the
DataList code in your *.aspx file as well.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Crazy Cat" <da******@hotma il.comwrote in message
news:bb******** *************** ***********@d45 g2000hsc.google groups.com...
Hi all,

I am developing an asp.net 2.0 application in Visual Studio 2005. On
my page I have a simple datalist that is bound programmaticall y to a
collection of simple objects. On this page I need to control the
visibility of a textbox based on a dropdown selection in the
datalist's edititem template. To do this, I registered a client script
block function and attached a client side handler for the
dropdownlist's onchange event in the datalist's OnItemCreated event.
The client script works fine, but I find that the update and cancel
events won't fire in the EditItem template. My edit, delete, and add
event fire fine in the ItemTemplate. I also find that if I remove the
client side onchange event handler the EditItem commands work fine.
Here is the code --
protected void Page_Load(objec t sender, EventArgs e)
{
// Register client script block containing the event handler for the
datalist's dropdownlist control.
ClientScriptMan ager csm = this.ClientScri pt;
string script = "function EnableCheckNumb erVisibility(Ty pe,
CheckNumber)\n" +
"{ \n" +
"if (Type.value == 'K') { \n" +
"CheckNumber.st yle.visibility = 'visible'; \n"
+
"} else {\n" +
"CheckNumber.st yle.visibility = 'hidden';\n" +
"}\n" +
"return true;\n" +
"}";
csm.RegisterCli entScriptBlock( this.GetType(),
"EnableCheckNum berVisibility", script,true);
if (!IsPostBack)
{
// Get Custom object collection out of session
Payments = BLL.Payments.ge tPaymentsByMemb erId("XXXXXX");
txtMemberAmount .Text =
Payments.Member Amount.ToString ("c");
txtDependentAmo unt.Text =
Payments.Depend entAmount.ToStr ing("c");
txtLateFee.Text = Payments.LateFe e.ToString("c") ;
txtAdminFee.Tex t = Payments.AdminF ee.ToString("c" );
txtTotalDues.Te xt = Payments.TotalD ues.ToString("c ");

Payments.Paymen tCollection.Add (new BLL.Payment());

PaymentTypes = BLL.Payment.get PaymentTypes();

dlPayments.Data Source = Payments.Paymen tCollection;
dlPayments.Data Bind();
}
}
protected void dlPayments_Item Command(object sender,
DataListCommand EventArgs e)
{
DataList dl = (DataList)sende r;

switch (e.CommandName)
{
case "add":
Payments.add(ne w BLL.Payment());

dlPayments.Data Source = Payments.Paymen tCollection;
dlPayments.Data Bind();
break;
}

}
protected void dlPayments_Item DataBound(objec t sender,
DataListItemEve ntArgs e)
{
if ((e.Item.ItemTy pe == ListItemType.It em) ||
(e.Item.ItemTyp e == ListItemType.Se lectedItem) ||
(e.Item.ItemTyp e == ListItemType.Al ternatingItem)
)
{
BLL.Payment p = (BLL.Payment)e. Item.DataItem;
foreach (ListItem i in PaymentTypes)
{
if (i.Value == p.TypeCode)
{
Label l =
(Label)e.Item.F indControl("lbl PaymentType");
l.Text = i.Text;
break;
}
}
}
}
protected void dlPayments_Item Created(object sender,
DataListItemEve ntArgs e)
{
// hook up the event handler here
if (e.Item.ItemTyp e == ListItemType.Ed itItem)
{
DropDownList dl =
(DropDownList)e .Item.FindContr ol("ddlType");

dl.Items.AddRan ge(PaymentTypes .ToArray());

TextBox tb =
(TextBox)e.Item .FindControl("t xtCheckNumber") ;

dl.Attributes["onchange"] = "EnableCheckNum berVisibility("
+ dl.ClientID + "," +
tb.ClientID + ");";

}
}
protected void dlPayments_Dele teCommand(objec t source,
DataListCommand EventArgs e)
{
if (e.Item.ItemInd ex 0)
{

Payments.remove (Payments.Payme ntCollection[e.Item.ItemInde x]);
((DataList)sour ce).DataSource =
Payments.Paymen tCollection;
dlPayments.Data Bind();
}

}
protected void dlPayments_Edit Command(object source,
DataListCommand EventArgs e)
{
((DataList)sour ce).EditItemInd ex = e.Item.ItemInde x;
((DataList)sour ce).DataSource = Payments.Paymen tCollection;
((DataList)sour ce).DataBind();
}
protected void dlPayments_Upda teCommand(objec t source,
DataListCommand EventArgs e)
{
DataList dl = (DataList)sourc e;

// Payment Type
DropDownList ddlType =
(DropDownList)e .Item.FindContr ol("ddlType");
Payments.Paymen tCollection[e.Item.ItemInde x].TypeCode =
ddlType.Selecte dValue;

// Amount
TextBox txtAmount = (TextBox)e.Item .FindControl("t xtAmount");
Payments.Paymen tCollection[e.Item.ItemInde x].Amount =
Single.Parse(tx tAmount.Text);

// Check Number
TextBox txtCheckNumber =
(TextBox)e.Item .FindControl("t xtCheckNumber") ;
Payments.Paymen tCollection[e.Item.ItemInde x].CheckNumber =
txtCheckNumber. Text;

dl.DataSource = Payments.Paymen tCollection;
dl.EditItemInde x = -1;
dl.DataBind();

}
protected void dlPayments_Canc elCommand(objec t source,
DataListCommand EventArgs e)
{
DataList dl = (DataList)sourc e;

dl.DataSource = Payments.Paymen tCollection;
dl.EditItemInde x = -1;
dl.DataBind();
}

Oct 14 '08 #2
On Oct 13, 9:15*pm, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
The first thing I am going to suggest is that you use a
System.Text.Str ingBuilder to create the JavaScript rather than a bunch of
concatenation operators (it is more efficient and the code is easier to
read).
Good tip. Thanks.

In your EnableCheckNumb erVisibility function, what is CheckNumber? If
it is one of the controls, it will not work because the ID used on the
client is not the one you enter server-side (you need to use the ClientId
property to get the generated ID, do a View Source in your browser to see
what I'm talking about).
CheckNumber is a textbox control and I am using ClientId (see the
ItemCreated
method where I attach the client side handler).

Also, when referencing an element in JavaScript,
you should always use the document.getEle mentById(elemen tid) method.
Initially, I used the getElementById method, but that actually caused
an error. Apparently the
javascript resolved the object name I passed it into a DOM element,
and when I attempted to
call getElementById with what it saw as an object and not a string, it
threw an exception.

Also, I
think it would be helpful to everyone in these newsgroups if you posted the
DataList code in your *.aspx file as well.
I'm not at the office now, but I will post the *.aspx file tomorrow.

Thanks for your suggestions.
--
Nathan Sokalski
njsokal...@hotm ail.comhttp://www.nathansokal ski.com/

"Crazy Cat" <danbr...@hotma il.comwrote in message

news:bb******** *************** ***********@d45 g2000hsc.google groups.com...
Hi all,
I am developing an asp.net 2.0 application in Visual Studio 2005. On
my page I have a simple datalist that is bound programmaticall y to a
collection of simple objects. On this page I need to control the
visibility of a textbox based on a dropdown selection in the
datalist's edititem template. To do this, I registered a client script
block function and attached a client side handler for the
dropdownlist's onchange event in the datalist's OnItemCreated event.
The client script works fine, but I find that the update and cancel
events won't fire in the EditItem template. My edit, delete, and add
event fire fine in the ItemTemplate. I also find that if I remove the
client side onchange event handler the EditItem commands work fine.
Here is the code --
* *protected void Page_Load(objec t sender, EventArgs e)
* *{
// Register client script block containing the event handler for the
datalist's dropdownlist control.
* * * *ClientScriptMa nager csm = this.ClientScri pt;
* * * *string script = "function EnableCheckNumb erVisibility(Ty pe,
CheckNumber)\n" +
* * * * * * * * * * * *"{ \n" +
* * * * * * * * * * * *"if (Type.value == 'K') { \n" +
* * * * * * * * * * * *"CheckNumber.s tyle.visibility = 'visible'; \n"
+
* * * * * * * * * * * *"} else {\n" +
* * * * * * * * * * * *"CheckNumber.s tyle.visibility = 'hidden';\n" +
* * * * * * * * * * * *"}\n" +
* * * * * * * * * * * *"return true;\n" +
* * * * * * * * * * * *"}";
* * * *csm.RegisterCl ientScriptBlock (this.GetType() ,
"EnableCheckNum berVisibility", script,true);
* * * *if (!IsPostBack)
* * * *{
// Get Custom object collection out of session
* * * * * *Payments = BLL.Payments.ge tPaymentsByMemb erId("XXXXXX");
* * * * * *txtMemberAmoun t.Text =
Payments.Member Amount.ToString ("c");
* * * * * *txtDependentAm ount.Text =
Payments.Depend entAmount.ToStr ing("c");
* * * * * *txtLateFee.Tex t = Payments.LateFe e.ToString("c") ;
* * * * * *txtAdminFee.Te xt = Payments.AdminF ee.ToString("c" );
* * * * * *txtTotalDues.T ext = Payments.TotalD ues.ToString("c ");
* * * * * *Payments.Payme ntCollection.Ad d(new BLL.Payment());
* * * * * *PaymentTypes = BLL.Payment.get PaymentTypes();
* * * * * *dlPayments.Dat aSource = Payments.Paymen tCollection;
* * * * * *dlPayments.Dat aBind();
* * * *}
* *}
* *protected void dlPayments_Item Command(object sender,
DataListCommand EventArgs e)
* *{
* * * *DataList dl = (DataList)sende r;
* * * *switch (e.CommandName)
* * * *{
* * * * * *case "add":
* * * * * * * *Payments.add(n ew BLL.Payment());
* * * * * * * *dlPayments.Dat aSource = Payments.Paymen tCollection;
* * * * * * * *dlPayments.Dat aBind();
* * * * * * * *break;
* * * *}
* *}
* *protected void dlPayments_Item DataBound(objec t sender,
DataListItemEve ntArgs e)
* *{
* * * *if ((e.Item.ItemTy pe == ListItemType.It em) ||
* * * * * *(e.Item.ItemTy pe == ListItemType.Se lectedItem) ||
* * * * * *(e.Item.ItemTy pe == ListItemType.Al ternatingItem)
* * * * * *)
* * * *{
* * * * * *BLL.Payment p = (BLL.Payment)e. Item.DataItem;
* * * * * *foreach (ListItem i in PaymentTypes)
* * * * * *{
* * * * * * * *if (i.Value == p.TypeCode)
* * * * * * * *{
* * * * * * * * * *Label l =
(Label)e.Item.F indControl("lbl PaymentType");
* * * * * * * * * *l.Text = i.Text;
* * * * * * * * * *break;
* * * * * * * *}
* * * * * *}
* * * *}
* *}
* *protected void dlPayments_Item Created(object sender,
DataListItemEve ntArgs e)
* *{
// hook up the event handler here
* * * *if (e.Item.ItemTyp e == ListItemType.Ed itItem)
* * * *{
* * * * * *DropDownList dl =
(DropDownList)e .Item.FindContr ol("ddlType");
* * * * * *dl.Items.AddRa nge(PaymentType s.ToArray());
* * * * * *TextBox tb =
(TextBox)e.Item .FindControl("t xtCheckNumber") ;
* * * * * *dl.Attributes["onchange"] = "EnableCheckNum berVisibility("
* * * * * * * * * * * * * * * * * ** *+ dl.ClientID + "," +
tb.ClientID + ");";
* * * *}
* *}
* *protected void dlPayments_Dele teCommand(objec t source,
DataListCommand EventArgs e)
* *{
* * * *if (e.Item.ItemInd ex 0)
* * * *{
Payments.remove (Payments.Payme ntCollection[e.Item.ItemInde x]);
* * * * * *((DataList)sou rce).DataSource =
Payments.Paymen tCollection;
* * * * * *dlPayments.Dat aBind();
* * * *}
* *}
* *protected void dlPayments_Edit Command(object source,
DataListCommand EventArgs e)
* *{
* * * *((DataList)sou rce).EditItemIn dex = e.Item.ItemInde x;
* * * *((DataList)sou rce).DataSource = Payments.Paymen tCollection;
* * * *((DataList)sou rce).DataBind() ;
* *}
* *protected void dlPayments_Upda teCommand(objec t source,
DataListCommand EventArgs e)
* *{
* * * *DataList dl = (DataList)sourc e;
* * * *// Payment Type
* * * *DropDownList ddlType =
(DropDownList)e .Item.FindContr ol("ddlType");
* * * *Payments.Payme ntCollection[e.Item.ItemInde x].TypeCode =
ddlType.Selecte dValue;
* * * *// Amount
* * * *TextBox txtAmount = (TextBox)e.Item .FindControl("t xtAmount");
* * * *Payments.Payme ntCollection[e.Item.ItemInde x].Amount =
Single.Parse(tx tAmount.Text);
* * * *// Check Number
* * * *TextBox txtCheckNumber =
(TextBox)e.Item .FindControl("t xtCheckNumber") ;
* * * *Payments.Payme ntCollection[e.Item.ItemInde x].CheckNumber=
txtCheckNumber. Text;
* * * *dl.DataSource = Payments.Paymen tCollection;
* * * *dl.EditItemInd ex = -1;
* * * *dl.DataBind();
* *}
* *protected void dlPayments_Canc elCommand(objec t source,
DataListCommand EventArgs e)
* *{
* * * *DataList dl = (DataList)sourc e;
* * * *dl.DataSource = Payments.Paymen tCollection;
* * * *dl.EditItemInd ex = -1;
* * * *dl.DataBind();
* *}
Oct 14 '08 #3
HI all,

I have additional info -- here is the markup for my datalist --

<asp:DataList ID="dlPayments "
runat="server"

OnCancelCommand ="dlPayments_Ca ncelCommand"

OnUpdateCommand ="dlPayments_Up dateCommand"
OnEditCommand=" dlPayments_Edit Command"

OnDeleteCommand ="dlPayments_De leteCommand"

OnItemDataBound ="dlPayments_It emDataBound"

OnItemCreated=" dlPayments_Item Created"

OnItemCommand=" dlPayments_Item Command" >
<HeaderTemplate >
<table width="410px" border="1"
cellpadding="2" cellspacing="2" class="tblCss" style="border-
color:#0066CC">
<thead>
<tr>
<th class="tblRowMa inCss"
style="width: 20%;">
Payment Type
</th>
<th class="tblRowMa inCss"
style="width: 20%;">
Amount
</th>
<th class="tblRowMa inCss"
style="width: *;">
Check Number <br />
(If Applicable)
</th>
</tr>
</thead>
</HeaderTemplate>
<FooterTemplate >
</table>
</FooterTemplate>
<ItemTemplate >
<tr>
<td class="tblRowMa inCss">
<asp:Label ID="lblPaymentT ype"
runat="server" Text='<%# Eval("TypeCode" ) %>'></asp:Label>
</td>
<td class="tblRowMa inCss">
<asp:Label ID="lblAmount"
runat="server" Text='<%# String.Format(" {0:C}",Eval("Am ount")) %>'></
asp:Label>
</td>
<td class="tblRowMa inCss">
<asp:Label ID="lblCheckNum ber"
runat="server" Text='<%# Eval("CheckNumb er") %>'></asp:Label>
</td>
<td class="tblRowMa inCss">
<asp:LinkButt on ID="lbSelect"
runat="server"
Text="Edit"
CommandName="ed it">
</asp:LinkButton>
<asp:LinkButt on ID="LinkButton1 "
runat="server"
Text="Add"
CommandName="ad d">
</asp:LinkButton>
<asp:LinkButt on ID="LinkButton2 "
runat="server"
Text="Delete"
CommandName="De lete">
</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<EditItemTempla te>
<tr>
<td class="tblRowMa inCss">
<asp:DropDownLi st ID="ddlType"
DataValueField= '<%#
Eval("TypeCode" ) %>'
runat="server">
</asp:DropDownLis t>
</td>
<td class="tblRowMa inCss">
<asp:TextBox ID="txtAmount"
runat="server" Text='<%# Eval("Amount") %>'></asp:TextBox>
</td>
<td class="tblRowMa inCss">
<asp:TextBox ID="txtCheckNum ber"
runat="server" Text='<%# Eval("CheckNumb er") %>'></asp:TextBox>
</td>
<td>
<asp:LinkButt on ID="LinkButton2 "
runat="server"
Text="Save Changes"
CommandName="up date">
</asp:LinkButton>
<asp:LinkButt on ID="LinkButton3 "
runat="server"
Text="Cancel"
CommandName="ca ncel">
</asp:LinkButton>
</td>
</tr>
</EditItemTemplat e>
</asp:DataList>
On Oct 13, 10:56*pm, Crazy Cat <danbr...@hotma il.comwrote:
On Oct 13, 9:15*pm, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
The first thing I am going to suggest is that you use a
System.Text.Str ingBuilder to create the JavaScript rather than a bunch of
concatenation operators (it is more efficient and the code is easier to
read).

Good tip. Thanks.

*In your EnableCheckNumb erVisibility function, what is CheckNumber? If
it is one of the controls, it will not work because the ID used on the
client is not the one you enter server-side (you need to use the ClientId
property to get the generated ID, do a View Source in your browser to see
what I'm talking about).

CheckNumber is a textbox control and I am using ClientId (see the
ItemCreated
method where I attach the client side handler).

Also, when referencing an element in JavaScript,
you should always use the document.getEle mentById(elemen tid) method.

Initially, I used the getElementById method, but that actually caused
an error. Apparently the
javascript resolved the object name I passed it into a DOM element,
and when I attempted to
call getElementById with what it saw as an object and not a string, it
threw an exception.

Also, I
think it would be helpful to everyone in these newsgroups if you postedthe
DataList code in your *.aspx file as well.

I'm not at the office now, but I will post the *.aspx file tomorrow.

Thanks for your suggestions.
--
Nathan Sokalski
njsokal...@hotm ail.comhttp://www.nathansokal ski.com/
"Crazy Cat" <danbr...@hotma il.comwrote in message
news:bb******** *************** ***********@d45 g2000hsc.google groups.com....
Hi all,
I am developing an asp.net 2.0 application in Visual Studio 2005. On
my page I have a simple datalist that is bound programmaticall y to a
collection of simple objects. On this page I need to control the
visibility of a textbox based on a dropdown selection in the
datalist's edititem template. To do this, I registered a client script
block function and attached a client side handler for the
dropdownlist's onchange event in the datalist's OnItemCreated event.
The client script works fine, but I find that the update and cancel
events won't fire in the EditItem template. My edit, delete, and add
event fire fine in the ItemTemplate. I also find that if I remove the
client side onchange event handler the EditItem commands work fine.
Here is the code --
* *protected void Page_Load(objec t sender, EventArgs e)
* *{
// Register client script block containing the event handler for the
datalist's dropdownlist control.
* * * *ClientScriptMa nager csm = this.ClientScri pt;
* * * *string script = "function EnableCheckNumb erVisibility(Ty pe,
CheckNumber)\n" +
* * * * * * * * * * * *"{ \n" +
* * * * * * * * * * * *"if (Type.value =='K') { \n" +
* * * * * * * * * * * *"CheckNumber.s tyle.visibility = 'visible'; \n"
+
* * * * * * * * * * * *"} else {\n" +
* * * * * * * * * * * *"CheckNumber.s tyle.visibility = 'hidden';\n" +
* * * * * * * * * * * *"}\n" +
* * * * * * * * * * * *"return true;\n" +
* * * * * * * * * * * *"}";
* * * *csm.RegisterCl ientScriptBlock (this.GetType() ,
"EnableCheckNum berVisibility", script,true);
* * * *if (!IsPostBack)
* * * *{
// Get Custom object collection out of session
* * * * * *Payments = BLL.Payments.ge tPaymentsByMemb erId("XXXXXX");
* * * * * *txtMemberAmoun t.Text =
Payments.Member Amount.ToString ("c");
* * * * * *txtDependentAm ount.Text =
Payments.Depend entAmount.ToStr ing("c");
* * * * * *txtLateFee.Tex t = Payments.LateFe e.ToString("c") ;
* * * * * *txtAdminFee.Te xt = Payments.AdminF ee.ToString("c" );
* * * * * *txtTotalDues.T ext = Payments.TotalD ues.ToString("c ");
* * * * * *Payments.Payme ntCollection.Ad d(new BLL.Payment());
* * * * * *PaymentTypes = BLL.Payment.get PaymentTypes();
* * * * * *dlPayments.Dat aSource = Payments.Paymen tCollection;
* * * * * *dlPayments.Dat aBind();
* * * *}
* *}
* *protected void dlPayments_Item Command(object sender,
DataListCommand EventArgs e)
* *{
* * * *DataList dl = (DataList)sende r;
* * * *switch (e.CommandName)
* * * *{
* * * * * *case "add":
* * * * * * * *Payments.add(n ew BLL.Payment());
* * * * * * * *dlPayments.Dat aSource = Payments.Paymen tCollection;
* * * * * * * *dlPayments.Dat aBind();
* * * * * * * *break;
* * * *}
* *}
* *protected void dlPayments_Item DataBound(objec t sender,
DataListItemEve ntArgs e)
* *{
* * * *if ((e.Item.ItemTy pe == ListItemType.It em) ||
* * * * * *(e.Item.ItemTy pe == ListItemType.Se lectedItem) ||
* * * * * *(e.Item.ItemTy pe == ListItemType.Al ternatingItem)
* * * * * *)
* * * *{
* * * * * *BLL.Payment p = (BLL.Payment)e. Item.DataItem;
* * * * * *foreach (ListItem i in PaymentTypes)
* * * * * *{
* * * * * * * *if (i.Value == p.TypeCode)
* * * * * * * *{
* * * * * * * * * *Label l =
(Label)e.Item.F indControl("lbl PaymentType");
* * * * * * * * * *l.Text = i.Text;
* * * * * * * * * *break;
* * * * * * * *}
* * * * * *}
* * * *}
* *}
* *protected void dlPayments_Item Created(object sender,
DataListItemEve ntArgs e)
* *{
// hook up the event handler here
* * * *if (e.Item.ItemTyp e == ListItemType.Ed itItem)
* * * *{
* * * * * *DropDownList dl =
(DropDownList)e .Item.FindContr ol("ddlType");
* * * * * *dl.Items.AddRa nge(PaymentType s.ToArray());
* * * * * *TextBox tb =
(TextBox)e.Item .FindControl("t xtCheckNumber") ;
* * * * * *dl.Attributes["onchange"] = "EnableCheckNum berVisibility("
* * * * * * * * * * * * * * * * * * * *+ dl.ClientID + "," +
tb.ClientID + ");";
* * * *}
* *}
* *protected void dlPayments_Dele teCommand(objec t source,
DataListCommand EventArgs e)
* *{
* * * *if (e.Item.ItemInd ex 0)
* * * *{
Payments.remove (Payments.Payme ntCollection[e.Item.ItemInde x]);
* * * * * *((DataList)sou rce).DataSource =
Payments.Paymen tCollection;
* * * * * *dlPayments.Dat aBind();
* * * *}
* *}
* *protected void dlPayments_Edit Command(object source,
DataListCommand EventArgs e)
* *{
* * * *((DataList)sou rce).EditItemIn dex = e.Item.ItemInde x;
* * * *((DataList)sou rce).DataSource = Payments.Paymen tCollection;
* * * *((DataList)sou rce).DataBind() ;
* *}
* *protected void dlPayments_Upda teCommand(objec t source,
DataListCommand EventArgs e)
* *{
* * * *DataList dl = (DataList)sourc e;
* * * *// Payment Type
* * * *DropDownList ddlType =
(DropDownList)e .Item.FindContr ol("ddlType");
* * * *Payments.Payme ntCollection[e.Item.ItemInde x].TypeCode =
ddlType.Selecte dValue;
* * * *// Amount
* * * *TextBox txtAmount = (TextBox)e.Item .FindControl("t xtAmount");
* * * *Payments.Payme ntCollection[e.Item.ItemInde x].Amount =
Single.Parse(tx tAmount.Text);
* * * *// Check Number
* * * *TextBox txtCheckNumber =
(TextBox)e.Item .FindControl("t xtCheckNumber") ;
* * * *Payments.Payme ntCollection[e.Item.ItemInde x].CheckNumber =
txtCheckNumber. Text;
* * * *dl.DataSource = Payments.Paymen tCollection;
* * * *dl.EditItemInd ex = -1;
* * * *dl.DataBind();
* *}
* *protected void dlPayments_Canc elCommand(objec t source,
DataListCommand EventArgs e)
* *{
* * * *DataList dl = (DataList)sourc e;
* * * *dl.DataSource = Payments.Paymen tCollection;
* * * *dl.EditItemInd ex = -1;
* * * *dl.DataBind();
* *}- Hide quoted text -

- Show quoted text -
Oct 14 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1056
by: Barry | last post by:
Hi, I have a sub in a user control that looks like this: Public Sub BatchDetail_ItemCommand(ByVal Sender As Object, ByVal e As DataListCommandEventArgs) Dim cmd As String = CType(e.CommandSource, LinkButton).CommandName Dim senderlist As DataList = CType(Sender, DataList)
3
4733
by: Hardy Wang | last post by:
Hi all; I have a DataList with ItemCreated event like below: private void myList_ItemCreated(object sender , DataListItemEventArgs e) { DataRowView myRowView; DataRow myRow; if (e.Item.DataItem != null) { Trace.Write(e.Item.ItemType.ToString(), "---with data"); } else { Trace.Write(e.Item.ItemType.ToString(), "---without data"); }
1
1382
by: jack | last post by:
Hello, I have a editable DataList, and would like the Edit Button to be appear or not appear dynamically based on the access the logged in person has. I have tried to use the visible=false, with no luck. Any help would be great an example in VB.NET would be the most helpful. Thanks in advance for your time and help,
8
7440
by: Adam Billmeier | last post by:
Problem: I am trying to use FindControl to grab a dropdownlist that is in the EditItemTemplate of a Datalist and then Bind it to a dataset. I also then need to put the correct values in all of the text boxes in the EditItemTemplate. I have set the EditItemIndex for the Datalist to -1, and then bound the Datalist. I then want to Bind the DropDown, and populate the values. All attempts to use FindControl on the control return "Nothing"
0
1062
by: Luis Esteban Valencia | last post by:
Hi, I'm in serious need of help. I have a datalist that will list a number of 'Agents'. When the user selects the edit button of my datalist, I put it into edit mode. When putting the datalist into edit mode I need to load the controls that I have placed inside the 'EditItemTemplate' section of the datalist. I cannot, however do this as I can't seem to find the controls. I have tried using datalist.findcontrol(datalist.edititemindex) and...
0
900
by: Scott K | last post by:
I have a datalist which has an edititem template. When the user is in edit mode (of the datalist) it shows a couple of text boxes for editing as well as a drop down list box and has a label control. When the user changes the item in the drop down list I would like to set the labels text property to a different description. My problem is I have the event that can be triggered when the Drop down selected index changes but can't seem to get...
1
1929
by: Jim Heavey | last post by:
First time trying to use the Datalist and I can not seem to get the events to fire. I set up my Data List control and I identify the event for the "OnEditCommand". I also set up an "<ItemTemplate>" in which I place a ASP:Button control in and I specify the "CommandName" property for this button to be "edit". I ensure that my control has the Datasource propery set to my DataTable. When I press the button in the DataList control, the...
1
2160
by: Neil Jarman | last post by:
Hi, I'm new to this today, and I've got some test code (see below.) The data loads fine. I can't understand why any of the events fire. Once the page loads, clicking on thew button from the ItemTemplate does not fire the OnItemCommand event. It just fires a page reload - as a postback. I guess I'm missing something really obvious and important here?
1
3779
by: Arielle | last post by:
Background: I have a generated datalist to display information and I need to add the capability to have a button (Edit button) so that users can change the information. I'm sure once I figure it out I'll smack myself on the head for being so stupid but I feel as though right now I'm chasing my tail and want to see if some of yall can point me in a better direction. Initiation public class GroupDetail : WebPart { //... DataList...
0
10579
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10633
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7814
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7007
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5674
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5852
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4479
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3126
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.