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

[Solved] DataSet into RadGrid

4 Answers 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tiago
Top achievements
Rank 2
Tiago asked on 22 Dec 2009, 04:34 PM
Dear friends,

Take a look at the following code:

webappteste.WebReferenceX.Service1 sd = new webappteste.WebReferenceX.Service1(); 
DataSet ds = new DataSet(); 
ds = sd.getClientes(); //Get full list of customers from a web service
DataTable dt = new DataTable("clientes"); 
dt = ds.Tables[0]; 
RadGrid1.DataSource = dt; 
int asd = dt.Columns.Count; //Returns 58 columns - CORRECT
string tableName = ds.Tables[0].Columns[0].ToString(); //Returns the column name "CLIENTE" - CORRECT
int b = ds.Tables[0].Columns.Count; //Returns 58 columns - CORRECT
int a = RadGrid1.Columns.Count; //Return 0 columns - WRONG - Why not 58 columns???

Can you tell me why this is happening?
Is there any other way to load a DataSet into a RadGrid?

Thanks in advance!!

WebService:

[WebMethod]
public DataSet getClientes() 
  SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT * FROM CLIENTES ORDER BY    NOME",connections.retConn()) 
  DataSet dataSet = new DataSet(); 
  dataAdapter.Fill(dataSet); 
  return dataSet 

4 Answers, 1 is accepted

Sort by
0
Accepted
Schlurk
Top achievements
Rank 2
answered on 22 Dec 2009, 09:26 PM
You haven't bound the data yet. This should help:

webappteste.WebReferenceX.Service1 sd = new webappteste.WebReferenceX.Service1();  
DataSet ds = new DataSet();  
ds = sd.getClientes(); //Get full list of customers from a web service 
DataTable dt = new DataTable("clientes");  
dt = ds.Tables[0];  
RadGrid1.DataSource = dt;  
RadGrid1.DataBind(); 
int asd = dt.Columns.Count; //Returns 58 columns - CORRECT 
string tableName = ds.Tables[0].Columns[0].ToString(); //Returns the column name "CLIENTE" - CORRECT 
int b = ds.Tables[0].Columns.Count; //Returns 58 columns - CORRECT 
int a = RadGrid1.Columns.Count; //Return 0 columns - WRONG - Why not 58 columns??? 

0
Tiago
Top achievements
Rank 2
answered on 23 Dec 2009, 09:29 AM
Dear friends,

Thank you for your help. Unfortunetly the problem remains, even with the
RadGrid1.DataBind() 
I reallly don't understand ... am i missing something? :(

Thanks once again.
0
Tiago
Top achievements
Rank 2
answered on 23 Dec 2009, 11:54 AM
Problem solved!

As basic as i needed to define the RadGrid first, like so:

 private void createGrid() 
 { 
        RadGrid1.Width = Unit.Pixel(900); 
        RadGrid1.HorizontalAlign = HorizontalAlign.Center; 
        RadGrid1.PageSize = 5; 
        RadGrid1.AllowPaging = true
        RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric; 
        RadGrid1.AutoGenerateColumns = false
 
        RadGrid1.MasterTableView.PageSize = 15; 
        RadGrid1.MasterTableView.Width = Unit.Pixel(900); 
        RadGrid1.MasterTableView.DataKeyNames = new string[] { "CLIENTE" }; 
        GridBoundColumn boundColumn = new GridBoundColumn(); 
        boundColumn.DataField = "CLIENTE"
        boundColumn.HeaderText = "Id. Cliente"
        boundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center; 
        boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Left; 
        RadGrid1.MasterTableView.Columns.Add(boundColumn); 
        boundColumn = new GridBoundColumn(); 
        boundColumn.DataField = "NOME"
        boundColumn.HeaderText = "Nome"
        boundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center; 
        boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Left; 
        RadGrid1.MasterTableView.Columns.Add(boundColumn); 
    } 

Another thing ... i am using google chrome to browse, and the grid is not centered ... why?

Take a look at the code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title></title
    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" /> 
    <style type="text/css"
        #form1 
        { 
            text-align: center; 
        } 
    </style> 
</head> 
<body> 
    <form id="form1" runat="server"
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        <Scripts> 
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" /> 
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" /> 
        </Scripts> 
    </telerik:RadScriptManager> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
    </telerik:RadAjaxManager> 
    <telerik:RadGrid ID="RadGrid1" runat="server" Width="666px"  
        AutoGenerateColumns="False" GridLines="None" Skin="Office2007" HorizontalAlign"center"
         
    </telerik:RadGrid> 
    </form> 
</body> 
</html> 

Once again, thanks in advance. :)
0
Tiago
Top achievements
Rank 2
answered on 28 Dec 2009, 03:36 PM
Found it myself ...

The best way to achieve this is to build the Grid in the Wizard mode, and only then make the dataset as the datasource.

If anyone need some source code, just let me know.

Thanks Schlurk, as you were the only one that tried to help me!
Tags
Grid
Asked by
Tiago
Top achievements
Rank 2
Answers by
Schlurk
Top achievements
Rank 2
Tiago
Top achievements
Rank 2
Share this question
or