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

trouble with grid in tabstrip

5 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
pshah
Top achievements
Rank 1
pshah asked on 09 Dec 2010, 02:41 PM
Hello friends,
I think i have a simple problem with the radgrid....that i cannot figure out....
please kindly help me in fixing what i am doing incorrectly,
i have written all the issue details in the attached project file. 
file linked below: Grid333 . zip
[URL=http://www.easy-share.com/1913236826/Grid333.zip]http://www.easy-share.com/1913236826/Grid333.zip[/URL]
[URL=http://www.mediafire.com/file/mcxxvce8uj3g4jh/Grid333.zip]http://www.mediafire.com/file/mcxxvce8uj3g4jh/Grid333.zip[/URL]
[URL=http://www.slingfile.com/file/6icllc]http://www.slingfile.com/file/6icllc[/URL]

Thanks and regards
prad



5 Answers, 1 is accepted

Sort by
0
pshah
Top achievements
Rank 1
answered on 09 Dec 2010, 02:44 PM
all links invalid! they were deleted automatically...
will post code here

0
pshah
Top achievements
Rank 1
answered on 10 Dec 2010, 07:29 AM
thought of posting the code here...
//just realized that the company policy forbids posting of any code online.
so i have trimmed to the required parts

issue:

I have tried my best to see and learn from all the examples - telerik demos and the forum ...

Using .NET 3.5, MSSQL, (masterpages+usercontrols+update panels)

>> need to use with table with  columns(Varchar(255)) with dynamic names              
its query will be created dynamically and the columns names will be dynamic strings
<b>Issues</b>:
grouping,filtering,sorting,paging,postback...grid disappears??  (i must
       be doing something terribly stupid!)
on row select...cannot show values of selected columns client side,

Sorry to bother you for my simple issues. But please help me! 




cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI.Grid;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using Telerik.Web.UI;
 
public partial class _Default22 : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadData();
 
        }
    }
 
    private void LoadData()
    {
                        RadGrid1.DataSource = GetDataTable("Select * from datatable1  ");
    }
 
    protected void SelectedIndexChanged(object sender, EventArgs e)
    {
        GridBoundColumn colDates =
            RadGrid1.Columns.FindByUniqueName("Dates") as GridBoundColumn;
        colDates.DataFormatString = ComboDates.SelectedValue;
 
        this.RadGrid1.Rebind();
    }
 
 
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
       
    }
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
    {
        foreach (GridDataItem item1 in RadGrid1.MasterTableView.Items)
        {
            if (item1.Selected)
            {
                item1.ForeColor = System.Drawing.Color.Brown;
                int pageIndex12 = RadGrid1.MasterTableView.PageCount;
            
            }
            else
            {
                item1.ForeColor = System.Drawing.Color.Black;
            }
 
        }
       
 
    public DataTable GetDataTable(string query)
    {
        String ConnString = "Data Source=.\\sqlexpress;Initial Catalog=file;Integrated Security=True";
        SqlConnection conn = new SqlConnection(ConnString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(query, conn);
 
        DataTable myDataTable = new DataTable();
 
        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
        }
        finally
        {
            conn.Close();
        }
 
        return myDataTable;
    }
 
 
    protected void RadGrid1_PageIndexChanged(object source, Telerik.Web.UI.GridPageChangedEventArgs e)
    {
        LoadData();
    }
   

}
0
Accepted
Tsvetina
Telerik team
answered on 14 Dec 2010, 04:47 PM
Hi,

From what I see in your code, you are not binding your RadGrid control correctly and most probably this is causing the issues with its datasource-related functionalities.

What you should do is handle the NeedDataSource event of RadGrid and move the LoadData() method call to it (there is no point in assigning the DataSource in Page_Load when using advanced data-binding. So, your code should look like that:
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    LoadData();
}

Also, you do not have to call LoadData() on PageIndexChanged, since the grid will fire NeedDataSource every time it needs to rebind its data (including when paging).

All the best,
Tsvetina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
pshah
Top achievements
Rank 1
answered on 15 Dec 2010, 09:18 AM
HELLO,
THANKS FOR YOUR PROMPT AND VALUABLE RESPONSE
I WILL TRY WITH YOUR SOLUTION AND GET BACK...

REGARDS
0
pshah
Top achievements
Rank 1
answered on 15 Dec 2010, 11:33 AM
Thanks Tsvetina !
Your solution is correct and it works.
Here after i will first read the documentation more carefully .

Regards
Pradip Shah
Tags
Grid
Asked by
pshah
Top achievements
Rank 1
Answers by
pshah
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or