views:

992

answers:

3

Hey guys,

I'm working on an ASP.NET page, and have a DataList with a non-visible label, ID, inside of it. The Datalist is populated by Query A.

I'm trying to add a handler in my VB code where it will run Query B, populating a different label in the Item Template, after ID is changed. I figure I need to go somewhere in the DataList, but poking through Intellisense and a google search weren't successful. Does anyone know how I get to that label? Sorry if this is a dumb question, and thanks for the help.

Edit: I see how I can access the datalist items while inside the function, but how do I do it for only one part of the DataList control in the Event Handler? All the options I'm seeing are related to full events involving the Data List, not a single label changing. Thanks.

Edit 2:

I figured I'd add some code, to better explain exactly the exact issue I'm having.

                <asp:DataList ID="DataList1" runat="server" DataSourceID="Omitted,Ilikemyjob">
                <ItemTemplate>
                      <asp:Label ID="FromLabel" runat="server" Font-Size="Small" Text='<%# Eval("IncdntDate") %>'></asp:Label><br />
                      <asp:Label ID="ToLabel" runat="server" Font-Size="Small" Text='<%# Eval("Roadway") %>'></asp:Label><br />
                      <asp:Label ID = "lblCrossroad" runat ="server" Font-Size = "Small" Text = '<%# Eval("Crossroad") %>'></asp:Label><br />
                      <asp:Label ID = "lblRdwyID" runat ="server" Font-Size="Small" Visible = "false" Text = '<%# Eval ("RdwyID") %>'></asp:Label>
                      <asp:Label ID = "DistanceLabel" runat ="server" Font-Size = "Small" Text = '<%# Eval("RptTime") %>'></asp:Label><br />
                      <asp:Label ID = "lblTTime" runat ="server" Font-Size = "small" visible ="false"></asp:Label>
                      <hr />
                 </ItemTemplate>
            </asp:DataList><br />

There's the DataList thing I'm doing, and I have a different query that I want to store the value of to lblTTime if lblRdwyID is set to a certain range of values, thought it will not always be set to a value.

I'm trying to set up an event that will trigger when lblRdwyID is set, that will launch the other query and set the value of that templated items lblTTime and make it visible. Is there a good way to do this? I tried messing around with DataList1's events, but couldn't get anything to do the trick.

A: 

Assuming you have the row, you use:

row.FindControl("mylabelid")

eglasius
+1  A: 

If your label has its visibility set to false, it won't render on the screen (as opposed to having a div block with visibility set to hidden), and so I wager that is why you can't actually find the control after the binding has occurred.

Have you tried using the DataKey property to store the ID instead? It is easily accessible at the row level and you can store additional data if needs be.

Dillie-O
@Dillie-O the OP seems to be talking server side, so even if it isn't rendered to the client it won't affect it. That said, if all the OP is to get the row's ID, I agree on using the DataKeys instead.
eglasius
A: 

how can enter data of database in label? can enter data of database in label?