Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datalist reading controls 1

Status
Not open for further replies.

checkai

Programmer
Jan 17, 2003
1,629
US
For some reason, I am unable to get the text values from the 2 label controls within a datalist...can someone see something wrong that I'm doing? The datakey returns the number, but nothing else does...

Code:
Sub dlstKPI_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlstKPI.ItemCommand
   Try
      Me.lblReportID.Text = Me.dlstKPI.DataKeys(e.Item.ItemIndex)
      Me.lblReportDescription.Text = CType(e.Item.FindControl("lblKPIDesc"), Label).Text
      Me.lblName.Text = CType(e.Item.FindControl("lblKPIName"), Label).Text
    Catch ex As Exception
      Dim fp As New ClientCare.errorCatcher
      fp.showMeTheError(ex)
      fp = Nothing
    End Try
  End Sub

html
Code:
<asp:DataList id="dlstKPI" style="Z-INDEX: 100; LEFT: 56px; POSITION: absolute; TOP: 56px" runat="server"
RepeatColumns="2" OnItemCommand="dlstKPI_ItemCommand" DataKeyField="reportID" RepeatDirection="Horizontal"
ShowFooter="False" ShowHeader="False">
<ItemTemplate>
 <TABLE id="Table1" style="WIDTH: 272px; HEIGHT: 20px" cellSpacing="1" cellPadding="1" width="272" border="0">
   <TR>
     <TD style="WIDTH: 22px">
	<asp:ImageButton id="btnRID" runat="server" ImageUrl="images/kpiLogo.gif" CommandName="select">
        </asp:ImageButton>
     </TD>
     <TD>
	<asp:Label id="lblKPIName" runat="server" Font-Names="Arial" Font-Size="13px" Font-Bold="True" Font-Italic="True"><%# Databinder.Eval(Container,"DataItem.Name") %>
	</asp:Label></TD>
    </TR>
</TABLE>
<asp:Label id="lblKPIDesc" runat="server" Visible="False">
<%# Databinder.Eval(Container,"DataItem.Description") %>
</asp:Label>
</ItemTemplate>
</asp:DataList>
 
If you want to get the value out w/ code (as opposed to only displaying it), then you need to assign it using the Text attribute of the Label. For example:
Code:
<asp:Label id="lblKPIName" runat="server" Font-Names="Arial" Font-Size="13px" Font-Bold="True" Font-Italic="True" Text='<%# Databinder.Eval(Container,"DataItem.Name") %>' />
:)
-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
I knew it was something small that I overlooked! Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top