Getting attribute or GetDataKeyValue Problem OnNeedDataSource for a Listview inside other listview

3 posts, 0 answers
  1. Cuneyt
    Cuneyt avatar
    36 posts
    Member since:
    Dec 2011

    Posted 18 Feb 2014 Link to this post

    Hi. I have nested listview . Child Listview has onneeddatasource. but i cant Access any DataKeyValue or custom control attribute in  OnNeedDataSource . both listviews are inside ajaxpanel.
    There is an old post about it here. strange i can reach these values from itemcommand of child listview, But i cant access anything from needdatasource event. thanks.

    basic skeleton:

    <telerik:RadAjaxPanel ID="apanelParent" runat="server"
                    ViewStateMode="Enabled"
                    EnableViewState="true">
         <telerik:RadListView ID="lvParent" runat="server"
                        DataKeyNames="CId"
                        DataSourceID="OADLSParent"
                        ViewStateMode="Enabled"
                        EnableViewState="true">
                   <ItemTemplate>
                             <asp:HiddenField ID="hfCid2" runat="server" Value='<%# Eval("CId") %>' />
                              <telerik:RadAjaxPanel ID="apanelChild" runat="server"
                  ViewStateMode="Enabled" EnableViewState="true">
                          <telerik:RadButton ID="btnShowChildInsertItem" runat="server"
                                            ViewStateMode="Enabled"
                                            EnableViewState="true"
                                            Text="insert input"
                                            OnClick="btnShowChildInsertItem_Click"
                                            cId='<%# Eval("CId") %>'
                                            CommandArgument='<%#Container.DataItemIndex%>'>
                        </telerik:RadButton>
                        <telerik:RadListView ID="lvChild" runat="server"
                                            DataKeyNames="Id"
                                            EnableViewState="true"
                                            ViewStateMode="Enabled"
                                            InsertItemPosition="FirstItem"
                                            AllowPaging="True"
                                            PageSize="5"
                                            OnNeedDataSource="lvChild_NeedDataSource"
                                            OnItemCommand="lvChild_ItemCommand">
                        </telerik:RadListView>
                       </telerik:RadAjaxPanel>
                  </ItemTemplate>
           </telerik:RadListView>
      </telerik:RadAjaxPanel>

     
    OnNeedDataSource of child:

    protected void lvChild_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
           {
                   RadListView lvChild = (RadListView)sender;
                   RadListViewDataItem parentItem = (RadListViewDataItem)lvChild.NamingContainer;
     
                  var parentCevapId = (int)parentItem.GetDataKeyValue("CId");//null.null exception
     
                   RadButton rb = (RadButton)parentItem.FindControl("btnShowChildInsertItem");
                   int cId = Convert.ToInt32(rb.Attributes["cId"]);//null.there is rb but no attr.
     
                   HiddenField hf2 = (HiddenField)parentItem.FindControl("hfCid2");
    //there is an hf2 but no value
                   string cId3 = hf2.Value.ToString();//null

  2. Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 24 Feb 2014 Link to this post

    Hello Cuneyt,

    I made a runnable demo based on your code. I'm afraid however that I'm unable to reproduce the problem you mentioned. Please download the attached demo (runnable website with assemblies removed) and let me know whether it works properly at your side. If it does, you can try replacing the datasource for the outer ListView with your own datasource. Let me know if I'm missing something.

    Regards,
    Daniel
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Cuneyt
    Cuneyt avatar
    36 posts
    Member since:
    Dec 2011

    Posted 26 Feb 2014 in reply to Daniel Link to this post

    Thank you. I had mistake about binding location of child listview. I filled child listview in parent itemdatabound event. Problem is solved. Regads. Thank you for your patient.
Back to Top