473,507 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I wire up a button in a datalist template?

using vb.net 1.1 I have a datalist and in it's item template I have 2
buttons, 'edit' and 'ShipToThisAddress'. The edit button works fine and it
opens up the edit template as it works with the edit command. But the how
do I wire ShipToThisAddress button? Its going to submit the address ID to
the database and do a redirect to another page. In the process of doing
this, it will need to get the row index in the datalist so I can get the
address ID from the datalist's keys collection.

Thanks.

--
mo*******@nospam.com
Nov 18 '05 #1
3 2719
OK I partially solved my problem, but I didn't answer my question. In
btnShipTo I used the item command by inputting 'item' in the command name
property for btnShipTo in the designer. Then in the codebehind I used the
following event to get the items key as a result of the button's the click
event and do something with it.

Private Sub dlAddresses_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
dlAddresses.ItemCommand
Dim key As String = dlAddresses.DataKeys.Item(e.Item.ItemIndex)
Console.WriteLine(key)
End Sub

HOWEVER

suppose this command was already being used for something like Selecting the
list item as the online documentation suggests. Then I would have to wire
up btnShipTo from scratch. How would I do that?

--
mo*******@nospam.com
"moondaddy" <mo*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
using vb.net 1.1 I have a datalist and in it's item template I have 2
buttons, 'edit' and 'ShipToThisAddress'. The edit button works fine and it opens up the edit template as it works with the edit command. But the how
do I wire ShipToThisAddress button? Its going to submit the address ID to
the database and do a redirect to another page. In the process of doing
this, it will need to get the row index in the datalist so I can get the
address ID from the datalist's keys collection.

Thanks.

--
mo*******@nospam.com

Nov 18 '05 #2
If you fill CommandName and CommandArgument of LinkButton you can use
ItemCommand event for handle event end get address ID for redirect!

In this way you can write code similar this :

[c# - CodeBehind]
private void DataList1_ItemCommand(object source, DataListCommandEventArgs
e)
{
if (e.CommandName.ToString() == "SkipTo")
{
string addressId = e.CommandArgument.ToString();
}
}

[ASP:NET]
<asp:DataList id="DataList1" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lbtSkip" Runat=server CommandName="SkipTo"
CommandArgument="<%# DataBinder.Eval(Container.DataItem, "AddressID")
%>"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>

"moondaddy" <mo*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
using vb.net 1.1 I have a datalist and in it's item template I have 2
buttons, 'edit' and 'ShipToThisAddress'. The edit button works fine and it opens up the edit template as it works with the edit command. But the how
do I wire ShipToThisAddress button? Its going to submit the address ID to
the database and do a redirect to another page. In the process of doing
this, it will need to get the row index in the datalist so I can get the
address ID from the datalist's keys collection.

Thanks.

--
mo*******@nospam.com

Nov 18 '05 #3
Thanks that worked great. I didn't realize that you have multiple buttons
use the item command event. Then in the item command event use a select
case for the command argument to handle each button differently.

--
mo*******@nospam.com
"Bruno Sirianni" <br***********@virgilio.it> wrote in message
news:Lv*********************@news4.tin.it...
If you fill CommandName and CommandArgument of LinkButton you can use
ItemCommand event for handle event end get address ID for redirect!

In this way you can write code similar this :

[c# - CodeBehind]
private void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName.ToString() == "SkipTo")
{
string addressId = e.CommandArgument.ToString();
}
}

[ASP:NET]
<asp:DataList id="DataList1" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lbtSkip" Runat=server CommandName="SkipTo"
CommandArgument="<%# DataBinder.Eval(Container.DataItem, "AddressID")
%>"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>

"moondaddy" <mo*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
using vb.net 1.1 I have a datalist and in it's item template I have 2
buttons, 'edit' and 'ShipToThisAddress'. The edit button works fine and

it
opens up the edit template as it works with the edit command. But the how do I wire ShipToThisAddress button? Its going to submit the address ID to the database and do a redirect to another page. In the process of doing
this, it will need to get the row index in the datalist so I can get the
address ID from the datalist's keys collection.

Thanks.

--
mo*******@nospam.com


Nov 18 '05 #4

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

Similar topics

1
1868
by: moondaddy | last post by:
I have a datalist that makes use of the edit template. In this template I also have client side validation controls for required fields. My problem is that when I click on the cancel button it...
3
319
by: moondaddy | last post by:
using vb.net 1.1 I have a datalist and in it's item template I have 2 buttons, 'edit' and 'ShipToThisAddress'. The edit button works fine and it opens up the edit template as it works with the...
3
2693
by: pierre.basson | last post by:
Hi, I have a DataList with an Item Template that contains an image and three radio buttons, which are used to indicate the image's status. How can I set the appropriate radio button to checked,...
1
1398
by: jagdishl | last post by:
Hi: I have a datalist which is populated dynamically based on a query.I have to place a submit button after datalist (not in the footer template) so that after pressing the submit button a final...
2
4699
by: Jack | last post by:
Hello, I need to add extra buttons to a datalist, but I don't know to add them to the control. I need to use the onCommand Functions, like OnUpdate, OnEdit, OnUpdate, OnCanel, Etc. I would...
3
10279
by: Mirek Endys | last post by:
I have DataList as part of DataList item. DataList in DataList. The parent DataList working well including Edit command, that shows Edit template and correctly bind the data into edit template...
16
12130
by: Vikas Kumar | last post by:
i am selectin some data from database and through reader showing it in datalist as above now for radio buttons i have single column which returns 1,2,3 and according to that i want one of above...
2
1406
by: rhyme2ri2 | last post by:
Hi!! I'm using asp.net 1.1 I have a datalist which gets dynamic data which is of unbound size may be small sometimes and may be very very long sometimes....... Whatever the size of data may be...
3
2794
by: Crazy Cat | last post by:
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...
0
7223
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
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
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...
1
7034
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...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
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 ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
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...

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.