Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2004, 11:11 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default accesing values in DataList

Hi everybody!

Does anybody know how to obtain the value of elements in a DataList?

I know how to obtain the index of the actual element, but not its text.

Thanks

-------------------------------
World only exists into your mind.
 
Old March 3rd, 2004, 04:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You can use the SelectedItem property to access the selected item. Then you can access the Data Item property (which is a System.Data object, such as a DataRowView), or if you are using a control as a template in the DataList, you can use the Controls property to access the control in the column.

Hope this helps.
 
Old March 4th, 2004, 02:45 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi bmains!

I found something like this, but I don't use templates, and I don't know how to use the Data Item property. Could you be more specific, please?

-------------------------------
World only exists into your mind.
 
Old March 4th, 2004, 03:45 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry... I really use templates.

I have a DataList with the next templates:

                <ItemTemplate>
                    <asp:LinkButton id="id_producto" runat="server">
                        <%#DataBinder.Eval(Container.DataItem, "id_producto")%>
                    </asp:LinkButton>
                    <asp:Label id="Label2" runat="server" Width="30px"></asp:Label>
                    <asp:LinkButton id="LinkButton2" runat="server">
                        <%#DataBinder.Eval(Container.DataItem, "nombre")%>
                    </asp:LinkButton>
                </ItemTemplate>

If I try something like this:

            if (e.Item.FindControl("id_producto") != null )
                lblMensaje.Text = e.Item.FindControl("id_producto").ToString();

I only obtain the text "System.Web.UI.WebControls.LinkButton" (sic).

-------------------------------
World only exists into your mind.
 
Old March 4th, 2004, 10:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Try:

if (e.Item.FindControl("id_producto") != null )
                lblMensaje.Text = ((LinkButton) e.Item.FindControl("id_producto")).Text;

You have to convert the control to a LinkButton to access the text property.

I hope my C# syntax is correct; I'm a VB developer and only dabbled with C# a little.
 
Old March 4th, 2004, 11:24 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi bmanis,

You're right. And it really works with a source like this:

<asp:LinkButton id="LinkButton1" runat="server">test</asp:LinkButton>

but NOT if you're working with databinders:

<asp:LinkButton id="id_producto" runat="server">
   <%#DataBinder.Eval(Container.DataItem, "id_producto")%>
</asp:LinkButton>

Buuufff... I don't know nothing more to try. :(


-------------------------------
World only exists into your mind.
 
Old March 8th, 2004, 09:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Maybe you should try accessing the DataItem property. I'm not really familiar with it, except that you can convert it to a DataRow or DataRowView, then access the source.
 
Old March 8th, 2004, 09:24 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I solved days ago, in the way:

string sCodProducto = dsProductos.Tables[0].DefaultView[e.Item.ItemIndex].Row["id_producto"].ToString();

As you could see, I used the DataSet and DefaultView, both with DataListCommandEventArgs.

Thanks Anyway

-------------------------------
World only exists into your mind.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating boolean values using datalist Scripts82 ASP.NET 1.0 and 1.1 Basics 1 September 20th, 2006 04:17 AM
closing froms in while accesing other anukagni Access 4 May 11th, 2006 05:38 AM
Accesing COM+ components from c# txerra General .NET 2 June 24th, 2005 05:23 AM
Accesing Com+ components from c# txerra C# 1 June 22nd, 2005 06:10 AM
DataList original values at update time MColeman ASP.NET 1.x and 2.0 Application Design 2 February 19th, 2004 03:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.