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

Help Setting Up an Advance Databind

10 Answers 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 11 Nov 2008, 10:28 PM
I recently added a Grid to a test website and was playing around.  Upon doing so, I setup the Grid to pull data from one table in my database, lets call it test.mdb.

I want it to pull data from two tables in that database.  How can I do it?  Once table is called Services and the other is Service_Categories.  I want the data to be grouped based on the Service_Category.

Thanks,
   TheShirey

10 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Nov 2008, 04:25 AM
Hi Matt,

If the data resides in different datatables, you can use a join/union clause in your select statement and then include the resulting fields in the RadGrid.

Shinu

0
Matt
Top achievements
Rank 1
answered on 12 Nov 2008, 04:30 AM
Shinu,

   Thanks for the quick response.  I'm new to RadControls.  I used the "dummy" setup available to configure my database connection to the grid.  Can you shed a little more light on this for me?  The two tables are inside the same database.
0
Princy
Top achievements
Rank 2
answered on 12 Nov 2008, 07:18 AM
Hello Matt,

You can refer to this link to understand the use of outerjoin sql command which would be apt for your scernario.
Outer Join

Thanks
Princy.
0
Yavor
Telerik team
answered on 12 Nov 2008, 07:23 AM
Hello Matt,

Also, attached to this message, is a small working project, which demonstrates a union with advanced databinding.
I hope it helps.

Best wishes,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Matt
Top achievements
Rank 1
answered on 12 Nov 2008, 11:32 PM
Okay,

    I've just watched the RadGrid-Netsted Tables Telerik Trainer video.  My only question left is, how can I make my table load specific data based on a menu item clicked on.  I'm hoping this can be done.

Thanks,
   TheShirey
0
Yavor
Telerik team
answered on 13 Nov 2008, 07:41 AM
Hello Matt,

To see more information on this possibility, please refer to the following article.
I hope this helps.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Matt
Top achievements
Rank 1
answered on 14 Nov 2008, 12:02 AM
Okay,  I have looked at the page you send me and it will work great.  I have one question.  What if I want to show two items in one field???  Lets say that my main table looks like this:  Service_ID, Service_Name, Service_Description, Service_In_Home_Pirce, and Service_In_Store_Price .  What if I want to may my data show like this...


<table border="0" cellpadding="0" cellspacing="0"
  <tr> 
     <td> 
        <b>Service Name</b><br /><br /> 
        <i>Service Description</i> 
     </td> 
     <td> 
        Service_In_Home_Price 
     </td> 
     <td> 
        Service_In_Store_Price 
     </td> 
   </tr> 
</table> 

I don't want to show the data in a table but it was the easiest way for me to show it.  I'm wanting to populate it in a RadGrid.

Another problem I'm having is being able to show two items from the database in the same section like in the above table code.
0
Yavor
Telerik team
answered on 17 Nov 2008, 12:27 PM
Hello Matt,

The easiest way to achieve this would be to use a template column - you can nest all the fields in it. A sample setup will look something like:

.aspx
<telerik:GridTemplateColumn> 
                        <ItemTemplate> 
                            <table border="0" cellpadding="0" cellspacing="0">  
                                <tr> 
                                    <td> 
                                        <b>Service Name</b><br /> 
                                        <br /> 
                                        <i>Service Description</i> 
                                    </td> 
                                    <td> 
                                        <asp:Label runat="server" ID="Label1" 
                                         Text='<%# Eval("Service_In_Home_Price") %>'>  
                                        </asp:Label> 
                                    </td> 
                                    <td> 
                                          <asp:Label runat="server" ID="Label2" 
                                         Text='<%# Eval("Service_In_Store_Price") %>'>  
                                        </asp:Label> 
                                    </td> 
                                </tr> 
                            </table> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 

I hope this helps.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Anders
Top achievements
Rank 1
answered on 07 Jan 2009, 02:57 PM
How can I access the Label1 from the code behind in the above example?

How can you enable sorting on that grid?
0
Shinu
Top achievements
Rank 2
answered on 08 Jan 2009, 05:02 AM
Hi Anders,

Try the following code snippet to access the Label from a GridTemplateColumn. For this you need to set the UniqueName property for the TemplateColumn.

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            Label lbl = (Label)item["TemplateColumn"].FindControl("Label1"); 
        } 
        
    } 

For implementing Sorting in Grid you need to set AllowSorting property to true. You can also refer the following code library submission for implementing Sorting with sub columns in a GridTemplateColumn.
Individual filtering and sorting for "sub-columns" in template column

Shinu.

Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Matt
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Yavor
Telerik team
Anders
Top achievements
Rank 1
Share this question
or