473,387 Members | 1,624 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,387 software developers and data experts.

ASP Button in a Datalist

Hello,

I have a datalist that contains an asp button. I have the need to pass a
value that is bound to my datalist along the button when the on_click event
is fired. My datalist creates a button for each row in my datasource, so
each button needs to pass a unique value. My questions are:

1. How do I pass the value with the button without making it visible on the
button or form.
2. Is there a way to grab this value in the button's event parameters, the
sender as system.object or the e as system.eventArgs

This button was previosly an anchor tag that passed the value through the
HREF querystring, but I did not like how it lost all the viewstate when I
redirected back.

Any help is appreciated,
Thanks
Nov 17 '05 #1
2 14314
Chris,

The only controls that will have an event are PAGE level controls.
Once you place a button inside a Datalist, it is now a CHILD of the datalist
and will need to use the Datalist's events instead.

For the button, you will need to assign, through databinding, these
attributes

CommandArguement
CommandName

BUTTON EXAMPLE
<asp:button id="Button1" runat="server" text="Push me" commandarguement='<%#
Container.DataItem("primaryKey") %>' commandname="Action" />
This sets the CommandArguement equal to the primary key of the record.

Now, for the event that will occur when button is pushed - This is the
Datalist's ItemCommand Event

Private Sub DataList1_ItemCommand(source as object, e as datalisteventargs)
Handles Datalist1.ItemCommand
'Assign a variable to hold CommandArgument

Dim primaryKey as Integer
primaryKey = CInt(e.CommandArguement)

'use this primaryKey variable in logic below
'Also, if there are more than one button (edit, delete, copy, etc)
'You put that "Action" in the CommandName attribute and use like so...

If e.CommandName = "Delete" Then
OleDbCommand1.CommandText = "DELETE DISTINCT FROM table WHERE
[primaryKey]="& primaryKey &";"
End If

End sub

Hope this helps,
Severin

"Chris Fink" <ch***@chrisfink.com> wrote in message
news:e%***************@TK2MSFTNGP11.phx.gbl...
Hello,

I have a datalist that contains an asp button. I have the need to pass a
value that is bound to my datalist along the button when the on_click event is fired. My datalist creates a button for each row in my datasource, so
each button needs to pass a unique value. My questions are:

1. How do I pass the value with the button without making it visible on the button or form.
2. Is there a way to grab this value in the button's event parameters, the
sender as system.object or the e as system.eventArgs

This button was previosly an anchor tag that passed the value through the
HREF querystring, but I did not like how it lost all the viewstate when I
redirected back.

Any help is appreciated,
Thanks

Nov 17 '05 #2
Hi.

There is a way:

First, change the buttons in your list to be control
buttons so they are using the OnCommand event instead of
OnClick. That makes you able to add a command parameter to
the buttons.

This code is from an application I'm making now. The
list's DataSource is a dataset, and when the button is
pushed another page opens. I use the session object for
storing different kinds of data.

Hope this helps you!

Ingeborg
private void dataList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)
{
DataRowView drv = (DataRowView) e.Item.DataItem;

Button anyButton = (Button)e.Item.FindControl
("anyButton");
anyButton.Command += new
System.Web.UI.WebControls.CommandEventHandler
(anyButton_Command);
anyButton.CommandArgument = drv.Row["id"].ToString
();
}

protected void anyButton_Command(object sender,
System.Web.UI.WebControls.CommandEventArgs e)
{
Session["Id"] = int.Parse(e.CommandArgument.ToString
());
Response.Redirect("newpage.aspx");
}

-----Original Message-----
Hello,

I have a datalist that contains an asp button. I have the need to pass avalue that is bound to my datalist along the button when the on_click eventis fired. My datalist creates a button for each row in my datasource, soeach button needs to pass a unique value. My questions are:
1. How do I pass the value with the button without making it visible on thebutton or form.
2. Is there a way to grab this value in the button's event parameters, thesender as system.object or the e as system.eventArgs

This button was previosly an anchor tag that passed the value through theHREF querystring, but I did not like how it lost all the viewstate when Iredirected back.

Any help is appreciated,
Thanks
.

Nov 17 '05 #3

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

Similar topics

3
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
by: Chris | last post by:
Hi Folks, well I have this "small" problem with the footertemplate in a datalist. I added a button and a textbox to update the db with the given String of the Textbox. I already searched for...
2
by: Chris Fink | last post by:
This should be relatively simple but I am unable to find an asp:button tag in a datalist footer. I have tried it numerous ways including the FindControl method from the many events that the...
3
by: David Hearn | last post by:
I have a datalist that I have inserted a radio button into. The datalist populates with a list of items and each one has a radio button next to it. I need to use the radio button to allow the user...
3
by: Patrick Olurotimi Ige | last post by:
Can i have a Button in a Datalist? The button is for posting a form to the the Database FOr example:- <ASP:DataList id="heading0" RepeatLayout="Flow" RepeatDirection="Horizontal" ...
1
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
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...
2
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...
0
by: pavankumar106 | last post by:
Hi im stuck in sm simple pb ..im having a datalist in wich im having images and each image have a delete button below it.now wen I press delete button I shud be able to delete that image in dataset...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.