473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 programmatically 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(object sender, EventArgs e)
{
// Register client script block containing the event handler for the
datalist's dropdownlist control.
ClientScriptManager csm = this.ClientScript;
string script = "function EnableCheckNumberVisibility(Type,
CheckNumber)\n" +
"{ \n" +
"if (Type.value == 'K') { \n" +
"CheckNumber.style.visibility = 'visible'; \n"
+
"} else {\n" +
"CheckNumber.style.visibility = 'hidden';\n" +
"}\n" +
"return true;\n" +
"}";
csm.RegisterClientScriptBlock(this.GetType(),
"EnableCheckNumberVisibility", script,true);
if (!IsPostBack)
{
// Get Custom object collection out of session
Payments = BLL.Payments.getPaymentsByMemberId("XXXXXX");
txtMemberAmount.Text =
Payments.MemberAmount.ToString("c");
txtDependentAmount.Text =
Payments.DependentAmount.ToString("c");
txtLateFee.Text = Payments.LateFee.ToString("c");
txtAdminFee.Text = Payments.AdminFee.ToString("c");
txtTotalDues.Text = Payments.TotalDues.ToString("c");

Payments.PaymentCollection.Add(new BLL.Payment());

PaymentTypes = BLL.Payment.getPaymentTypes();

dlPayments.DataSource = Payments.PaymentCollection;
dlPayments.DataBind();
}
}
protected void dlPayments_ItemCommand(object sender,
DataListCommandEventArgs e)
{
DataList dl = (DataList)sender;

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

dlPayments.DataSource = Payments.PaymentCollection;
dlPayments.DataBind();
break;
}

}
protected void dlPayments_ItemDataBound(object sender,
DataListItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.SelectedItem) ||
(e.Item.ItemType == ListItemType.AlternatingItem)
)
{
BLL.Payment p = (BLL.Payment)e.Item.DataItem;
foreach (ListItem i in PaymentTypes)
{
if (i.Value == p.TypeCode)
{
Label l =
(Label)e.Item.FindControl("lblPaymentType");
l.Text = i.Text;
break;
}
}
}
}
protected void dlPayments_ItemCreated(object sender,
DataListItemEventArgs e)
{
// hook up the event handler here
if (e.Item.ItemType == ListItemType.EditItem)
{
DropDownList dl =
(DropDownList)e.Item.FindControl("ddlType");

dl.Items.AddRange(PaymentTypes.ToArray());

TextBox tb =
(TextBox)e.Item.FindControl("txtCheckNumber");

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

}
}
protected void dlPayments_DeleteCommand(object source,
DataListCommandEventArgs e)
{
if (e.Item.ItemIndex 0)
{

Payments.remove(Payments.PaymentCollection[e.Item.ItemIndex]);
((DataList)source).DataSource =
Payments.PaymentCollection;
dlPayments.DataBind();
}

}
protected void dlPayments_EditCommand(object source,
DataListCommandEventArgs e)
{
((DataList)source).EditItemIndex = e.Item.ItemIndex;
((DataList)source).DataSource = Payments.PaymentCollection;
((DataList)source).DataBind();
}
protected void dlPayments_UpdateCommand(object source,
DataListCommandEventArgs e)
{
DataList dl = (DataList)source;

// Payment Type
DropDownList ddlType =
(DropDownList)e.Item.FindControl("ddlType");
Payments.PaymentCollection[e.Item.ItemIndex].TypeCode =
ddlType.SelectedValue;

// Amount
TextBox txtAmount = (TextBox)e.Item.FindControl("txtAmount");
Payments.PaymentCollection[e.Item.ItemIndex].Amount =
Single.Parse(txtAmount.Text);

// Check Number
TextBox txtCheckNumber =
(TextBox)e.Item.FindControl("txtCheckNumber");
Payments.PaymentCollection[e.Item.ItemIndex].CheckNumber =
txtCheckNumber.Text;

dl.DataSource = Payments.PaymentCollection;
dl.EditItemIndex = -1;
dl.DataBind();

}
protected void dlPayments_CancelCommand(object source,
DataListCommandEventArgs e)
{
DataList dl = (DataList)source;

dl.DataSource = Payments.PaymentCollection;
dl.EditItemIndex = -1;
dl.DataBind();
}
Oct 13 '08 #1
3 2781
The first thing I am going to suggest is that you use a
System.Text.StringBuilder to create the JavaScript rather than a bunch of
concatenation operators (it is more efficient and the code is easier to
read). In your EnableCheckNumberVisibility 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.getElementById(elementid) 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********@hotmail.com
http://www.nathansokalski.com/

"Crazy Cat" <da******@hotmail.comwrote in message
news:bb**********************************@d45g2000 hsc.googlegroups.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 programmatically 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(object sender, EventArgs e)
{
// Register client script block containing the event handler for the
datalist's dropdownlist control.
ClientScriptManager csm = this.ClientScript;
string script = "function EnableCheckNumberVisibility(Type,
CheckNumber)\n" +
"{ \n" +
"if (Type.value == 'K') { \n" +
"CheckNumber.style.visibility = 'visible'; \n"
+
"} else {\n" +
"CheckNumber.style.visibility = 'hidden';\n" +
"}\n" +
"return true;\n" +
"}";
csm.RegisterClientScriptBlock(this.GetType(),
"EnableCheckNumberVisibility", script,true);
if (!IsPostBack)
{
// Get Custom object collection out of session
Payments = BLL.Payments.getPaymentsByMemberId("XXXXXX");
txtMemberAmount.Text =
Payments.MemberAmount.ToString("c");
txtDependentAmount.Text =
Payments.DependentAmount.ToString("c");
txtLateFee.Text = Payments.LateFee.ToString("c");
txtAdminFee.Text = Payments.AdminFee.ToString("c");
txtTotalDues.Text = Payments.TotalDues.ToString("c");

Payments.PaymentCollection.Add(new BLL.Payment());

PaymentTypes = BLL.Payment.getPaymentTypes();

dlPayments.DataSource = Payments.PaymentCollection;
dlPayments.DataBind();
}
}
protected void dlPayments_ItemCommand(object sender,
DataListCommandEventArgs e)
{
DataList dl = (DataList)sender;

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

dlPayments.DataSource = Payments.PaymentCollection;
dlPayments.DataBind();
break;
}

}
protected void dlPayments_ItemDataBound(object sender,
DataListItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.SelectedItem) ||
(e.Item.ItemType == ListItemType.AlternatingItem)
)
{
BLL.Payment p = (BLL.Payment)e.Item.DataItem;
foreach (ListItem i in PaymentTypes)
{
if (i.Value == p.TypeCode)
{
Label l =
(Label)e.Item.FindControl("lblPaymentType");
l.Text = i.Text;
break;
}
}
}
}
protected void dlPayments_ItemCreated(object sender,
DataListItemEventArgs e)
{
// hook up the event handler here
if (e.Item.ItemType == ListItemType.EditItem)
{
DropDownList dl =
(DropDownList)e.Item.FindControl("ddlType");

dl.Items.AddRange(PaymentTypes.ToArray());

TextBox tb =
(TextBox)e.Item.FindControl("txtCheckNumber");

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

}
}
protected void dlPayments_DeleteCommand(object source,
DataListCommandEventArgs e)
{
if (e.Item.ItemIndex 0)
{

Payments.remove(Payments.PaymentCollection[e.Item.ItemIndex]);
((DataList)source).DataSource =
Payments.PaymentCollection;
dlPayments.DataBind();
}

}
protected void dlPayments_EditCommand(object source,
DataListCommandEventArgs e)
{
((DataList)source).EditItemIndex = e.Item.ItemIndex;
((DataList)source).DataSource = Payments.PaymentCollection;
((DataList)source).DataBind();
}
protected void dlPayments_UpdateCommand(object source,
DataListCommandEventArgs e)
{
DataList dl = (DataList)source;

// Payment Type
DropDownList ddlType =
(DropDownList)e.Item.FindControl("ddlType");
Payments.PaymentCollection[e.Item.ItemIndex].TypeCode =
ddlType.SelectedValue;

// Amount
TextBox txtAmount = (TextBox)e.Item.FindControl("txtAmount");
Payments.PaymentCollection[e.Item.ItemIndex].Amount =
Single.Parse(txtAmount.Text);

// Check Number
TextBox txtCheckNumber =
(TextBox)e.Item.FindControl("txtCheckNumber");
Payments.PaymentCollection[e.Item.ItemIndex].CheckNumber =
txtCheckNumber.Text;

dl.DataSource = Payments.PaymentCollection;
dl.EditItemIndex = -1;
dl.DataBind();

}
protected void dlPayments_CancelCommand(object source,
DataListCommandEventArgs e)
{
DataList dl = (DataList)source;

dl.DataSource = Payments.PaymentCollection;
dl.EditItemIndex = -1;
dl.DataBind();
}

Oct 14 '08 #2
On Oct 13, 9:15*pm, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
The first thing I am going to suggest is that you use a
System.Text.StringBuilder 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 EnableCheckNumberVisibility 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.getElementById(elementid) 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...@hotmail.comhttp://www.nathansokalski.com/

"Crazy Cat" <danbr...@hotmail.comwrote in message

news:bb**********************************@d45g2000 hsc.googlegroups.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 programmatically 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(object sender, EventArgs e)
* *{
// Register client script block containing the event handler for the
datalist's dropdownlist control.
* * * *ClientScriptManager csm = this.ClientScript;
* * * *string script = "function EnableCheckNumberVisibility(Type,
CheckNumber)\n" +
* * * * * * * * * * * *"{ \n" +
* * * * * * * * * * * *"if (Type.value == 'K') { \n" +
* * * * * * * * * * * *"CheckNumber.style.visibility = 'visible'; \n"
+
* * * * * * * * * * * *"} else {\n" +
* * * * * * * * * * * *"CheckNumber.style.visibility = 'hidden';\n" +
* * * * * * * * * * * *"}\n" +
* * * * * * * * * * * *"return true;\n" +
* * * * * * * * * * * *"}";
* * * *csm.RegisterClientScriptBlock(this.GetType(),
"EnableCheckNumberVisibility", script,true);
* * * *if (!IsPostBack)
* * * *{
// Get Custom object collection out of session
* * * * * *Payments = BLL.Payments.getPaymentsByMemberId("XXXXXX");
* * * * * *txtMemberAmount.Text =
Payments.MemberAmount.ToString("c");
* * * * * *txtDependentAmount.Text =
Payments.DependentAmount.ToString("c");
* * * * * *txtLateFee.Text = Payments.LateFee.ToString("c");
* * * * * *txtAdminFee.Text = Payments.AdminFee.ToString("c");
* * * * * *txtTotalDues.Text = Payments.TotalDues.ToString("c");
* * * * * *Payments.PaymentCollection.Add(new BLL.Payment());
* * * * * *PaymentTypes = BLL.Payment.getPaymentTypes();
* * * * * *dlPayments.DataSource = Payments.PaymentCollection;
* * * * * *dlPayments.DataBind();
* * * *}
* *}
* *protected void dlPayments_ItemCommand(object sender,
DataListCommandEventArgs e)
* *{
* * * *DataList dl = (DataList)sender;
* * * *switch (e.CommandName)
* * * *{
* * * * * *case "add":
* * * * * * * *Payments.add(new BLL.Payment());
* * * * * * * *dlPayments.DataSource = Payments.PaymentCollection;
* * * * * * * *dlPayments.DataBind();
* * * * * * * *break;
* * * *}
* *}
* *protected void dlPayments_ItemDataBound(object sender,
DataListItemEventArgs e)
* *{
* * * *if ((e.Item.ItemType == ListItemType.Item) ||
* * * * * *(e.Item.ItemType == ListItemType.SelectedItem) ||
* * * * * *(e.Item.ItemType == ListItemType.AlternatingItem)
* * * * * *)
* * * *{
* * * * * *BLL.Payment p = (BLL.Payment)e.Item.DataItem;
* * * * * *foreach (ListItem i in PaymentTypes)
* * * * * *{
* * * * * * * *if (i.Value == p.TypeCode)
* * * * * * * *{
* * * * * * * * * *Label l =
(Label)e.Item.FindControl("lblPaymentType");
* * * * * * * * * *l.Text = i.Text;
* * * * * * * * * *break;
* * * * * * * *}
* * * * * *}
* * * *}
* *}
* *protected void dlPayments_ItemCreated(object sender,
DataListItemEventArgs e)
* *{
// hook up the event handler here
* * * *if (e.Item.ItemType == ListItemType.EditItem)
* * * *{
* * * * * *DropDownList dl =
(DropDownList)e.Item.FindControl("ddlType");
* * * * * *dl.Items.AddRange(PaymentTypes.ToArray());
* * * * * *TextBox tb =
(TextBox)e.Item.FindControl("txtCheckNumber");
* * * * * *dl.Attributes["onchange"] = "EnableCheckNumberVisibility("
* * * * * * * * * * * * * * * * * ** *+ dl.ClientID + "," +
tb.ClientID + ");";
* * * *}
* *}
* *protected void dlPayments_DeleteCommand(object source,
DataListCommandEventArgs e)
* *{
* * * *if (e.Item.ItemIndex 0)
* * * *{
Payments.remove(Payments.PaymentCollection[e.Item.ItemIndex]);
* * * * * *((DataList)source).DataSource =
Payments.PaymentCollection;
* * * * * *dlPayments.DataBind();
* * * *}
* *}
* *protected void dlPayments_EditCommand(object source,
DataListCommandEventArgs e)
* *{
* * * *((DataList)source).EditItemIndex = e.Item.ItemIndex;
* * * *((DataList)source).DataSource = Payments.PaymentCollection;
* * * *((DataList)source).DataBind();
* *}
* *protected void dlPayments_UpdateCommand(object source,
DataListCommandEventArgs e)
* *{
* * * *DataList dl = (DataList)source;
* * * *// Payment Type
* * * *DropDownList ddlType =
(DropDownList)e.Item.FindControl("ddlType");
* * * *Payments.PaymentCollection[e.Item.ItemIndex].TypeCode =
ddlType.SelectedValue;
* * * *// Amount
* * * *TextBox txtAmount = (TextBox)e.Item.FindControl("txtAmount");
* * * *Payments.PaymentCollection[e.Item.ItemIndex].Amount =
Single.Parse(txtAmount.Text);
* * * *// Check Number
* * * *TextBox txtCheckNumber =
(TextBox)e.Item.FindControl("txtCheckNumber");
* * * *Payments.PaymentCollection[e.Item.ItemIndex].CheckNumber=
txtCheckNumber.Text;
* * * *dl.DataSource = Payments.PaymentCollection;
* * * *dl.EditItemIndex = -1;
* * * *dl.DataBind();
* *}
* *protected void dlPayments_CancelCommand(object source,
DataListCommandEventArgs e)
* *{
* * * *DataList dl = (DataList)source;
* * * *dl.DataSource = Payments.PaymentCollection;
* * * *dl.EditItemIndex = -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_CancelCommand"

OnUpdateCommand="dlPayments_UpdateCommand"
OnEditCommand="dlPayments_EditCommand"

OnDeleteCommand="dlPayments_DeleteCommand"

OnItemDataBound="dlPayments_ItemDataBound"

OnItemCreated="dlPayments_ItemCreated"

OnItemCommand="dlPayments_ItemCommand" >
<HeaderTemplate>
<table width="410px" border="1"
cellpadding="2" cellspacing="2" class="tblCss" style="border-
color:#0066CC">
<thead>
<tr>
<th class="tblRowMainCss"
style="width: 20%;">
Payment Type
</th>
<th class="tblRowMainCss"
style="width: 20%;">
Amount
</th>
<th class="tblRowMainCss"
style="width: *;">
Check Number <br />
(If Applicable)
</th>
</tr>
</thead>
</HeaderTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<ItemTemplate>
<tr>
<td class="tblRowMainCss">
<asp:Label ID="lblPaymentType"
runat="server" Text='<%# Eval("TypeCode") %>'></asp:Label>
</td>
<td class="tblRowMainCss">
<asp:Label ID="lblAmount"
runat="server" Text='<%# String.Format("{0:C}",Eval("Amount")) %>'></
asp:Label>
</td>
<td class="tblRowMainCss">
<asp:Label ID="lblCheckNumber"
runat="server" Text='<%# Eval("CheckNumber") %>'></asp:Label>
</td>
<td class="tblRowMainCss">
<asp:LinkButton ID="lbSelect"
runat="server"
Text="Edit"
CommandName="edit">
</asp:LinkButton>
<asp:LinkButton ID="LinkButton1"
runat="server"
Text="Add"
CommandName="add">
</asp:LinkButton>
<asp:LinkButton ID="LinkButton2"
runat="server"
Text="Delete"
CommandName="Delete">
</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td class="tblRowMainCss">
<asp:DropDownList ID="ddlType"
DataValueField='<%#
Eval("TypeCode") %>'
runat="server">
</asp:DropDownList>
</td>
<td class="tblRowMainCss">
<asp:TextBox ID="txtAmount"
runat="server" Text='<%# Eval("Amount") %>'></asp:TextBox>
</td>
<td class="tblRowMainCss">
<asp:TextBox ID="txtCheckNumber"
runat="server" Text='<%# Eval("CheckNumber") %>'></asp:TextBox>
</td>
<td>
<asp:LinkButton ID="LinkButton2"
runat="server"
Text="Save Changes"
CommandName="update">
</asp:LinkButton>
<asp:LinkButton ID="LinkButton3"
runat="server"
Text="Cancel"
CommandName="cancel">
</asp:LinkButton>
</td>
</tr>
</EditItemTemplate>
</asp:DataList>
On Oct 13, 10:56*pm, Crazy Cat <danbr...@hotmail.comwrote:
On Oct 13, 9:15*pm, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
The first thing I am going to suggest is that you use a
System.Text.StringBuilder 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 EnableCheckNumberVisibility 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.getElementById(elementid) 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...@hotmail.comhttp://www.nathansokalski.com/
"Crazy Cat" <danbr...@hotmail.comwrote in message
news:bb**********************************@d45g2000 hsc.googlegroups.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 programmatically 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(object sender, EventArgs e)
* *{
// Register client script block containing the event handler for the
datalist's dropdownlist control.
* * * *ClientScriptManager csm = this.ClientScript;
* * * *string script = "function EnableCheckNumberVisibility(Type,
CheckNumber)\n" +
* * * * * * * * * * * *"{ \n" +
* * * * * * * * * * * *"if (Type.value =='K') { \n" +
* * * * * * * * * * * *"CheckNumber.style.visibility = 'visible'; \n"
+
* * * * * * * * * * * *"} else {\n" +
* * * * * * * * * * * *"CheckNumber.style.visibility = 'hidden';\n" +
* * * * * * * * * * * *"}\n" +
* * * * * * * * * * * *"return true;\n" +
* * * * * * * * * * * *"}";
* * * *csm.RegisterClientScriptBlock(this.GetType(),
"EnableCheckNumberVisibility", script,true);
* * * *if (!IsPostBack)
* * * *{
// Get Custom object collection out of session
* * * * * *Payments = BLL.Payments.getPaymentsByMemberId("XXXXXX");
* * * * * *txtMemberAmount.Text =
Payments.MemberAmount.ToString("c");
* * * * * *txtDependentAmount.Text =
Payments.DependentAmount.ToString("c");
* * * * * *txtLateFee.Text = Payments.LateFee.ToString("c");
* * * * * *txtAdminFee.Text = Payments.AdminFee.ToString("c");
* * * * * *txtTotalDues.Text = Payments.TotalDues.ToString("c");
* * * * * *Payments.PaymentCollection.Add(new BLL.Payment());
* * * * * *PaymentTypes = BLL.Payment.getPaymentTypes();
* * * * * *dlPayments.DataSource = Payments.PaymentCollection;
* * * * * *dlPayments.DataBind();
* * * *}
* *}
* *protected void dlPayments_ItemCommand(object sender,
DataListCommandEventArgs e)
* *{
* * * *DataList dl = (DataList)sender;
* * * *switch (e.CommandName)
* * * *{
* * * * * *case "add":
* * * * * * * *Payments.add(new BLL.Payment());
* * * * * * * *dlPayments.DataSource = Payments.PaymentCollection;
* * * * * * * *dlPayments.DataBind();
* * * * * * * *break;
* * * *}
* *}
* *protected void dlPayments_ItemDataBound(object sender,
DataListItemEventArgs e)
* *{
* * * *if ((e.Item.ItemType == ListItemType.Item) ||
* * * * * *(e.Item.ItemType == ListItemType.SelectedItem) ||
* * * * * *(e.Item.ItemType == ListItemType.AlternatingItem)
* * * * * *)
* * * *{
* * * * * *BLL.Payment p = (BLL.Payment)e.Item.DataItem;
* * * * * *foreach (ListItem i in PaymentTypes)
* * * * * *{
* * * * * * * *if (i.Value == p.TypeCode)
* * * * * * * *{
* * * * * * * * * *Label l =
(Label)e.Item.FindControl("lblPaymentType");
* * * * * * * * * *l.Text = i.Text;
* * * * * * * * * *break;
* * * * * * * *}
* * * * * *}
* * * *}
* *}
* *protected void dlPayments_ItemCreated(object sender,
DataListItemEventArgs e)
* *{
// hook up the event handler here
* * * *if (e.Item.ItemType == ListItemType.EditItem)
* * * *{
* * * * * *DropDownList dl =
(DropDownList)e.Item.FindControl("ddlType");
* * * * * *dl.Items.AddRange(PaymentTypes.ToArray());
* * * * * *TextBox tb =
(TextBox)e.Item.FindControl("txtCheckNumber");
* * * * * *dl.Attributes["onchange"] = "EnableCheckNumberVisibility("
* * * * * * * * * * * * * * * * * * * *+ dl.ClientID + "," +
tb.ClientID + ");";
* * * *}
* *}
* *protected void dlPayments_DeleteCommand(object source,
DataListCommandEventArgs e)
* *{
* * * *if (e.Item.ItemIndex 0)
* * * *{
Payments.remove(Payments.PaymentCollection[e.Item.ItemIndex]);
* * * * * *((DataList)source).DataSource =
Payments.PaymentCollection;
* * * * * *dlPayments.DataBind();
* * * *}
* *}
* *protected void dlPayments_EditCommand(object source,
DataListCommandEventArgs e)
* *{
* * * *((DataList)source).EditItemIndex = e.Item.ItemIndex;
* * * *((DataList)source).DataSource = Payments.PaymentCollection;
* * * *((DataList)source).DataBind();
* *}
* *protected void dlPayments_UpdateCommand(object source,
DataListCommandEventArgs e)
* *{
* * * *DataList dl = (DataList)source;
* * * *// Payment Type
* * * *DropDownList ddlType =
(DropDownList)e.Item.FindControl("ddlType");
* * * *Payments.PaymentCollection[e.Item.ItemIndex].TypeCode =
ddlType.SelectedValue;
* * * *// Amount
* * * *TextBox txtAmount = (TextBox)e.Item.FindControl("txtAmount");
* * * *Payments.PaymentCollection[e.Item.ItemIndex].Amount =
Single.Parse(txtAmount.Text);
* * * *// Check Number
* * * *TextBox txtCheckNumber =
(TextBox)e.Item.FindControl("txtCheckNumber");
* * * *Payments.PaymentCollection[e.Item.ItemIndex].CheckNumber =
txtCheckNumber.Text;
* * * *dl.DataSource = Payments.PaymentCollection;
* * * *dl.EditItemIndex = -1;
* * * *dl.DataBind();
* *}
* *protected void dlPayments_CancelCommand(object source,
DataListCommandEventArgs e)
* *{
* * * *DataList dl = (DataList)source;
* * * *dl.DataSource = Payments.PaymentCollection;
* * * *dl.EditItemIndex = -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
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 =...
3
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...
1
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,...
8
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...
0
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...
0
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...
1
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...
1
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.