DataList hidden value submiting to different file in ASP.NET 2.0 beta

W

webserverpete

I am new to ASP.NET in general, but I do have experience with classic
ASP. I am using a DataList control with a hidden value to submit to a
different page, however I do not know how to get to that hidden value.
Here is my DataList control code:

<asp:DataList ID="DataList1" runat="server"
DataSourceID="SqlDataSource1" RepeatColumns="4">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "itemname")%> <br>
$<%#FormatNumber(DataBinder.Eval(Container.DataItem, "itemprice"),
2)%> <br>
<%#DataBinder.Eval(Container.DataItem, "itemdescription")%> <br>
<%#Format(DataBinder.Eval(Container.DataItem, "itemaddtime"), "ddd
MMMM d, yyyy h:mm tt")%> <br>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%#
"images/" & Eval("picfilename") %>' PostBackUrl='<%# "cart.aspx?id=" &
eval("itemid") %>' Width="200px" BorderStyle="None" /><br>
<asp:Button id="submit" runat="server" Text="Order" PostBackUrl='<%#
"cart.aspx?id=" & eval("itemid") %>' />
<asp:HiddenField runat="server" Value='<%# eval("itemid") %>'
ID="itemid" />
</ItemTemplate>
</asp:DataList>

What code to I need on cart.aspx to get the hidden value?
 
G

Grant Merwitz

a control in a datalist does not exist like a normal control on your page.
It needs to be casted as such

I too found this a hard concept to understand when changing from classic ASP
to .NET

NOw is this value your trying to get, record specific?
i.e. are you using one of the DataLists's inbuilt commands like the
OnItemCommand, or the OnEditCommand.

if so, you can get the value like follows:
((HiddenField)e.Item.FindControl("itemid")).Value; --> c#
ctype(e.Item.FindControl("itemid"), HiddenField).Value --> vb (something
like that, i'm not a vb coder)

If you are not trying to get this from a given item, but a more general
value for the whole datalist,
you can look at storing this hidden outside of the DataList, then you can
get it with:
itemid.Value
But as long as its in the datalist , you'll have to cast a specific items
hiddenfield

HTH
 
W

webserverpete

I think the code below is on the right track but I am not too sure:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
dim i as HiddenField
i =ctype(previouspage.FindControl("itemid"),HiddenField)
response.Write (i)
End Sub
 
G

Grant Merwitz

So your trying to push it into a new page, like a form post.

I'm not sure if that'll work, but worth a try.
You must try utilise the Postback feature in .NET, i find this far superior
than the ASP traditional form post.

Also, explore the in-build data commands in the datalist.
instead of EventArgs, you'll have DataListCommandEventArgs and that'll give
you access to controls within your datalist.

but if your code is working, its working
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top