Get Data Value From ListView ItemDataBound

前端 未结 4 1814
眼角桃花
眼角桃花 2021-01-04 05:24

I\'m sure I\'ve done this before but really cant remember how.

In the ItemDataBound event of a ListView I need to get the actual data value. I cant seem to find it i

相关标签:
4条回答
  • 2021-01-04 05:42
    <asp:ListView ID="ContactsListView" 
            DataSourceID="ContactsDataSource" 
            ConvertEmptyStringToNull="true"        
            OnItemDataBound="ContactsListView_ItemDataBound"
            runat="server">
            <LayoutTemplate>
              <table cellpadding="2" width="680px" border="0">
                <tr style="background-color: #ADD8E6" runat="server">
                    <th runat="server">First Name</th>
                    <th runat="server">Last Name</th>
                    <th runat="server">E-mail Address</th>
                </tr>
                <tr runat="server" id="itemPlaceholder" />
              </table>
              <asp:DataPager runat="server" ID="PeopleDataPager" PageSize="12">
                <Fields>
                  <asp:NumericPagerField ButtonCount="10" /> 
                </Fields>
              </asp:DataPager>
            </LayoutTemplate>
            <ItemTemplate>
              <tr style="background-color: #CAEEFF" runat="server">
                <td>
                  <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
                </td>
                <td>
                  <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
                </td>
                <td>
                  <asp:Label ID="EmailAddressLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
                </td>
              </tr>
            </ItemTemplate>
          </asp:ListView>
    

    Server side

    protected void ContactsListView_ItemDataBound(object sender, ListViewItemEventArgs e)
          {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
              // Display the e-mail address in italics.
              Label EmailAddressLabel = (Label)e.Item.FindControl("EmailAddressLabel");
              // EmailAddressLabel.Font.Italic = true;
              string valueoftheControl = EmailAddressLabel.Text;  
              /* you have to get the value like this. 
                 If its a dropdown or any other use their 
                 corresponding property to get the value.*/
            }
          }
    
    0 讨论(0)
  • 2021-01-04 06:01

    I think what you're after is the ListViewDataItem.DataItem

    0 讨论(0)
  • 2021-01-04 06:05
    protected void Score_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
    {
        if (e.Item is RadListViewItem)
        {
            RadListViewDataItem item = e.Item as RadListViewDataItem;
            object dataItem = ((System.Data.DataRowView)(((RadListViewDataItem)e.Item).DataItem)).Row.ItemArray[2].ToString();
            string raetest = Convert.ToString(dataItem);
        }
    }
    
    0 讨论(0)
  • 2021-01-04 06:07

    Use the ListViewDataItem in the ItemDataBound event:

    protected void yourListView_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        ListViewDataItem dataItem = (ListViewDataItem)e.Item;
    
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            YourDataSource yourDataSource= (YourDataSource )dataItem.DataItem;            
    
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题