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

[Solved] Prometheus RadGrid pagging issue

1 Answer 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
R Brown
Top achievements
Rank 1
R Brown asked on 31 Mar 2008, 06:03 PM
I have pagging enabled for my RadGrid, when I select the next page, the control moves to the next page but adds two additional coulums with the following data in them: System.Data.DataRowView

My code is below:

protected

void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

}

}

protected void Page_PreRender(object sender, EventArgs e)

{

this.BuildGrid();

}

protected void Page_Init(object source, System.EventArgs e)

{

}

private void BuildGrid()

{

GridBoundColumn boundColumn;

boundColumn = new GridBoundColumn();

boundColumn.DataField = "CountryId";

boundColumn.HeaderText = "Country Number";

this.RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn = new GridBoundColumn();

boundColumn.DataField = "CountryName";

boundColumn.HeaderText = "Country Name";

this.RadGrid1.MasterTableView.Columns.Add(boundColumn);

RadGrid1.Width = Unit.Percentage(50);

RadGrid1.PageSize = 50;

RadGrid1.AllowPaging = true;

RadGrid1.PagerStyle.Mode = Telerik.Web.UI.GridPagerMode.NextPrevNumericAndAdvanced;

RadGrid1.AutoGenerateColumns = false;

RadGrid1.ShowStatusBar = true;

RadGrid1.Skin = "Web20";

RadGrid1.ShowStatusBar = true;

RadGrid1.GridLines = GridLines.Horizontal;

RadGrid1.HorizontalAlign = HorizontalAlign.Left;

RadGrid1.ShowFooter = true;

RadGrid1.ShowHeader = true;

RadGrid1.ShowStatusBar = true;

RadGrid1.AllowSorting = true;

RadGrid1.Visible = true;

this.RadGrid1.DataSource = this.GetData();

this.RadGrid1.DataBind();

}

private DataSet GetData()

{

SqlConnection sqlConnection = new SqlConnection();

SqlCommand sqlCommand = new SqlCommand();

SqlParameter sqlParameter = new SqlParameter();

DataSet dataSet = new DataSet();

try

{

if (sqlConnection.State != ConnectionState.Open)

{

sqlConnection.ConnectionString = SqlConnectionString.GetConnectionString();

sqlConnection.Open();

}

sqlCommand.Connection = sqlConnection;

sqlCommand.CommandType = CommandType.StoredProcedure;

sqlCommand.CommandText = ApplicationStoredProcedures.GetCountries();

sqlCommand.Parameters.Add("@WebPageName", SqlDbType.NVarChar).Value = "Authors.aspx";

sqlCommand.Parameters.Add("@CultureCode", SqlDbType.NVarChar).Value = "en-US";

sqlCommand.Parameters.Add("@ControlName", SqlDbType.NVarChar).Value = "ddlCountry";

sqlCommand.ExecuteNonQuery();

SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);

sqlDataAdapter.Fill(dataSet);

return dataSet;

}

catch (SqlException sql)

{

throw sql;

}

catch (Exception ex)

{

throw ex;

}

finally

{

if (sqlConnection.State != ConnectionState.Closed)

{

sqlConnection.Close();

}

sqlCommand.Dispose();

}

}

public void RadGrid1_PageIndexChanged(object source, Telerik.Web.UI.GridPageChangedEventArgs e)

{

this.RadGrid1.CurrentPageIndex = e.NewPageIndex;

}

/// <summary>

/// You can get the exact numbers of rows in your RadGrid either directly from the DataSource or in the following manner in the ItemDataBound event:

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

{

if (e.Item is GridPagerItem)

{

Label1.Text = (e.Item as GridPagerItem).Paging.DataSourceCount.ToString();

}

}

 

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)

{

// RadGrid1.DataSource = this.GetData() ;

}

I cannot find the issue. Am I doing something wrong.

1 Answer, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 01 Apr 2008, 05:46 AM
Hello R Brown,

The reason for this behavior is that you create 2 columns and add them to MasterTableView's Columns collection on each postback. I suggest that you move the columns creation in Page_Init or in Page_Load in if (!IsPostBack) block. You can find more details here.

Kind regards,
Ves
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
R Brown
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or