Ask a Question related to ASP.NET General, Design and Development.
-
Chris Fink #1
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
Chris Fink Guest
-
datalist please help soon
H data I'm binding to the DataList is information about products in my product database. Perhaps passed in the QueryString to this page is a... -
DataList: how to use??
I am having difficulity understanding just exactly how to use the DataList (may be using it in the wrong context) Problem: I have a dataset that... -
ASP:DATALIST
Hello, Does anyone know of a way to prevent the asp:datalist control from creating html code table and table row tags when it is rendered. I... -
ASP DataList
Hello, I have an ASP Datalist in which I am binding a value within the <itemtemplate> section as follows: <%#... -
UpdateCommand with Datalist
Hi, I have a datalist that I use to display and edit records to a user. Datalist shown below; visual basic... -
sampsons #2
Re: ASP Button in a Datalist
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" <chris@chrisfink.com> wrote in message
news:e%23g45CkRDHA.940@TK2MSFTNGP11.phx.gbl...event> 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_clickthe> 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> 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
>
>
sampsons Guest
-
Ingeborg #3
ASP Button in a Datalist
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");
}
need to pass a>-----Original Message-----
>Hello,
>
>I have a datalist that contains an asp button. I have thethe on_click event>value that is bound to my datalist along the button whendatasource, so>is fired. My datalist creates a button for each row in myare:>each button needs to pass a unique value. My questionsit visible on the>
>1. How do I pass the value with the button without makingevent parameters, the>button or form.
>2. Is there a way to grab this value in the button'svalue through the>sender as system.object or the e as system.eventArgs
>
>This button was previosly an anchor tag that passed theviewstate when I>HREF querystring, but I did not like how it lost all the>redirected back.
>
>Any help is appreciated,
>Thanks
>
>
>.
>Ingeborg Guest



Reply With Quote

