This is a migrated thread and some comments may be shown as answers.

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

2 Answers 111 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Cuneyt
Top achievements
Rank 1
Cuneyt asked on 18 Feb 2014, 10:03 PM

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 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 24 Feb 2014, 09:45 AM
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.
0
Cuneyt
Top achievements
Rank 1
answered on 26 Feb 2014, 07:27 AM
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.
Tags
ListView
Asked by
Cuneyt
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Cuneyt
Top achievements
Rank 1
Share this question
or