 |
| 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
|
|
|
|

March 3rd, 2004, 11:11 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

March 3rd, 2004, 04:54 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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.
|
|

March 4th, 2004, 02:45 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

March 4th, 2004, 03:45 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

March 4th, 2004, 10:20 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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.
|
|

March 4th, 2004, 11:24 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

March 8th, 2004, 09:09 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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.
|
|

March 8th, 2004, 09:24 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |