Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 3rd, 2004, 11:11 AM
Authorized User
 
Join Date: Nov 2003
Location: Mataro, Barcelona, Spain.
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.
  #2 (permalink)  
Old March 3rd, 2004, 04:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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.
  #3 (permalink)  
Old March 4th, 2004, 02:45 AM
Authorized User
 
Join Date: Nov 2003
Location: Mataro, Barcelona, Spain.
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.
  #4 (permalink)  
Old March 4th, 2004, 03:45 AM
Authorized User
 
Join Date: Nov 2003
Location: Mataro, Barcelona, Spain.
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.
  #5 (permalink)  
Old March 4th, 2004, 10:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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.
  #6 (permalink)  
Old March 4th, 2004, 11:24 AM
Authorized User
 
Join Date: Nov 2003
Location: Mataro, Barcelona, Spain.
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.
  #7 (permalink)  
Old March 8th, 2004, 09:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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.
  #8 (permalink)  
Old March 8th, 2004, 09:24 AM
Authorized User
 
Join Date: Nov 2003
Location: Mataro, Barcelona, Spain.
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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:31 AM.


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