471,071 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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

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.DataIte m, "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?

Nov 19 '05 #1
3 3016
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
<we***********@ebtech.net> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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.DataIte m, "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?

Nov 19 '05 #2
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"),HiddenFi eld)
response.Write (i)
End Sub

Nov 19 '05 #3
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
<we***********@ebtech.net> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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"),HiddenFi eld)
response.Write (i)
End Sub

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Bruce W..1 | last post: by
3 posts views Thread by Bindia | last post: by
2 posts views Thread by scout3014 | last post: by
3 posts views Thread by JCCDevel | last post: by

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.