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

RadDock accessing controls

5 Answers 82 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 04 Nov 2013, 01:01 AM
Hi Everyone,

I'm new to telerik and I recently started to explore with it and love it.  I build a page with it and I want to have 3 separate collapsible Dock within one page.  I created it like this:

<telerik:RadDockLayout ID="RadDockLayout2" runat="server">
                            <telerik:RadDockZone ID="RadDockZone3" runat="server" Height="300px" Width="300px">
                                <telerik:RadDock ID="RadDock3" runat="server" Width="300px" Title="Dock1" Text="Dock1">
                                <Commands>
                                <telerik:DockExpandCollapseCommand />
                                </Commands>
                                <ContentTemplate>
                                  --Contents here---
                                </ContentTemplate>
                                </telerik:RadDock>
                            </telerik:RadDockZone>
                            <telerik:RadDockZone ID="RadDockZone4" runat="server" Height="300px" Width="300px">
                                <telerik:RadDock ID="RadDock4" runat="server" Width="300px" Title="Dock2" Text="Dock2">
                                <Commands>
                                <telerik:DockExpandCollapseCommand />
                                </Commands>
                                <ContentTemplate>
                                --Contents here---
                                </ContentTemplate>
                                </telerik:RadDock>
                            </telerik:RadDockZone>
 
                            <telerik:RadDockZone ID="RadDockZone5" runat="server" Height="300px" Width="300px">
                                <telerik:RadDock ID="RadDock5" runat="server" Width="300px" Title="Dock2" Text="Dock2">
                                <Commands>
                                <telerik:DockExpandCollapseCommand />
                                </Commands>
                                <ContentTemplate>
                                  --Contents here---
                                </ContentTemplate>
                                </telerik:RadDock>
                            </telerik:RadDockZone>
                        </telerik:RadDockLayout>

My problem is that I have some textbox/combobox in Dock1 and need to create a SqlDataSource in dock2 but  use the  textbox/combobox as variable in the SqlDataSource.  When I try to run it, I get a "Cannot find the Control" for SqlDataSource.  Is there any way I can work around  this or a simple way of creating such  page?

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 04 Nov 2013, 01:33 PM
Hi Anthony,

This is because the RadComboBox and SqlDataSource resides in different ContentTemplate of different RadDock and hence you cannot access the control the data source directly by its ID. Please have a look into the following sample code I tried which works fine.

ASPX:
<telerik:RadDockLayout ID="RadDockLayout1" runat="server">
    <telerik:RadDockZone ID="RadDockZone1" runat="server" Height="300px" Width="300px">
        <telerik:RadDock ID="RadDock1" runat="server" Width="300px" Title="Dock1" Text="Dock1">
            <Commands>
                <telerik:DockExpandCollapseCommand />
            </Commands>
            <ContentTemplate>
                <telerik:RadComboBox ID="RadComboBox1" runat="server">
                </telerik:RadComboBox>
            </ContentTemplate>
        </telerik:RadDock>
    </telerik:RadDockZone>
    <telerik:RadDockZone ID="RadDockZone2" runat="server" Height="300px" Width="300px">
        <telerik:RadDock ID="RadDock2" runat="server" Width="300px" Title="Dock2" Text="Dock2">
            <Commands>
                <telerik:DockExpandCollapseCommand />
            </Commands>
            <ContentTemplate>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                    SelectCommand="select ContactName from [Customers]"></asp:SqlDataSource>
            </ContentTemplate>
        </telerik:RadDock>
    </telerik:RadDockZone>
</telerik:RadDockLayout>

C#:
protected void Page_Load(object sender, EventArgs e)
{
    SqlDataSource datasource1 = (SqlDataSource)RadDock2.ContentContainer.FindControl("SqlDataSource1");
    RadComboBox1.DataSource = datasource1;
    RadComboBox1.DataTextField = "ContactName";
    RadComboBox1.DataBind();
}

Thanks,
Shinu.
0
Anthony
Top achievements
Rank 1
answered on 04 Nov 2013, 04:27 PM
Hi Shinu,

Thank you for your help but I run into another situation.  I also need to bind a RadDatePicker but its properties are a bit different and I can't get it to work.  Any idea on how to fix Date fields?

Thanks.
0
Shinu
Top achievements
Rank 1
answered on 05 Nov 2013, 12:17 PM
Hi Anthony,

I am not sure about your requirement. Can you please elaborate a bit more on your scenario along with the code you tried so that I can inspect it more deeply from my end?

Thanks,
Shinu.
0
Anthony
Top achievements
Rank 1
answered on 05 Nov 2013, 03:04 PM
Hi Shinu,

First of all, I'm new to computer programming so please forgive any incorrect wording I may used. I currently have a SqlDateSource that fills a RadGrid in  RadDock2 with 3 ControlParameter(CardDate, TrackCode and RaceNo). However, these 3 parameter is in RadDock1 and as you stated, I won't be able to access them since the are in a different ContentTemplate. Your previous solution would work for the RadComboBox but not the RadDatePicker.

<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnection %>"
        SelectCommand="usp_AppsSelListView" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:ControlParameter ControlID="RadDatePicker1" Name="CardDate" PropertyName="SelectedDate"
                Type="DateTime" />
            <asp:ControlParameter ControlID="RadComboBox1" Name="TrackCode" PropertyName="SelectedValue"
                Type="String" />
            <asp:ControlParameter ControlID="RadComboBox2" Name="RaceNo" PropertyName="SelectedValue"
                Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

So this get me thinking and I've come up with a solution but I'm not sure if it is the right approach and would love to know if there is a more efficient way of accomplishing this task.  This is what I did:

1) I create a Class call Race with 3 public properties.

public class Race
    {
        public DateTime RaceDate { get; set; }
        public string Track { get; set; }
        public string RaceNo { get; set; }
         
        public Race()
        {
        }
 
    }
Then on the Page_Load code block I did the below.
if (RadDatePicker1.SelectedDate == null && RadComboBox1.Text == null && RadComboBox2.Text == "")
           {
               //Do something here... 
           }
           else
           {
               Race nRace = new Race();
               nRace.RaceDate = Convert.ToDateTime(((RadDockZone1.FindControl("RadDock1") as RadDock).ContentContainer.FindControl("RadDatePicker1") as RadDatePicker).SelectedDate);
               nRace.Track = ((RadDockZone1.FindControl("RadDock1") as RadDock).ContentContainer.FindControl("RadComboBox1") as RadComboBox).Text;
               nRace.RaceNo = ((RadDockZone1.FindControl("RadDock1") as RadDock).ContentContainer.FindControl("RadComboBox2") as RadComboBox).Text;
 
               this.Session["RaceDate"] = nRace.RaceDate;
               this.Session["Track"] = nRace.Track;
               this.Session["RaceNo"] = nRace.RaceNo;
           }
Then I modify the SqlDataSource to used SessionParameter.

<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnection %>"
                        SelectCommand="usp_AppsSelListView" SelectCommandType="StoredProcedure">
                        <SelectParameters>
                            <asp:SessionParameter Name="CardDate" SessionField="RaceDate" Type="DateTime" />
                            <asp:SessionParameter Name="TrackCode" SessionField="Track" Type="String" />
                            <asp:SessionParameter Name="RaceNo" SessionField="RaceNo" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>

I did this last night and as I'm typing this to you I'm starting to think that I should make the class a "Static" and eliminate the instantiated.
What is your opinion?

Thank you,
Anthony
0
Accepted
Shinu
Top achievements
Rank 1
answered on 11 Nov 2013, 07:48 AM
Hi Anthony,

Please have a look into the following code I tried for your scenario. You can try the following approach so that you can avoid the use of an extra class in your C# code.

ASPX:
<telerik:RadDockLayout ID="RadDockLayout1" runat="server">
    <telerik:RadDockZone ID="RadDockZone1" runat="server" Height="300px" Width="300px">
        <telerik:RadDock ID="RadDock1" runat="server" Width="300px" Title="Dock1" Text="Dock1">
            <ContentTemplate>
                <br />
                <telerik:RadComboBox ID="RadComboBox1" runat="server" EmptyMessage="Select">
                    <Items>
                        <telerik:RadComboBoxItem runat="server" Text="GALED" Value="GALED" />
                        <telerik:RadComboBoxItem runat="server" Text="OTTIK" Value="OTTIK" />
                        <telerik:RadComboBoxItem runat="server" Text="FRANS" Value="FRANS" />
                    </Items>
                </telerik:RadComboBox>
                <br />
                <telerik:RadDatePicker ID="RadDatePicker1" runat="server">
                </telerik:RadDatePicker>
                <br />
                <telerik:RadButton ID="RadButton1" runat="server" Text="Populate Grid" OnClick="RadButton1_Click">
                </telerik:RadButton>
            </ContentTemplate>
        </telerik:RadDock>
    </telerik:RadDockZone>
    <telerik:RadDockZone ID="RadDockZone2" runat="server" Height="300px" Width="300px">
        <telerik:RadDock ID="RadDock2" runat="server" Width="300px" Title="Dock2" Text="Dock2">
            <ContentTemplate>
                <br />
                <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" DataSourceID="SqlDataSource1">
                </telerik:RadGrid>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                    SelectCommand="select OrderID, CustomerID, ShipCity from [Orders] where CustomerID=@CID and OrderDate<@Date">
                    <SelectParameters>
                        <asp:Parameter Name="CID" Type="String" />
                        <asp:Parameter Name="Date" Type="DateTime" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </ContentTemplate>
        </telerik:RadDock>
    </telerik:RadDockZone>
</telerik:RadDockLayout>

C#:
protected void Page_Load(object sender, EventArgs e)
{
    SqlDataSource1.SelectParameters["CID"].DefaultValue = RadComboBox1.SelectedValue;
    SqlDataSource1.SelectParameters["Date"].DefaultValue = RadDatePicker1.SelectedDate.ToString();
}
protected void RadButton1_Click(object sender, EventArgs e)
{
    RadGrid1.Rebind();
}

Thanks,
Shinu.
Tags
Dock
Asked by
Anthony
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Anthony
Top achievements
Rank 1
Share this question
or