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

RadGrid rebind on page previous page navigation

12 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JSON
Top achievements
Rank 1
JSON asked on 17 Jan 2012, 02:54 PM
On "page 1" of a project I have a radgrid bound to a datasource. After selecting a record from the list and navigating to "page 2" then changing record values. Upon returning to "page 1" - I need to rebind the grid to show changes. I have researched and tried many different options with no luck.

Thanks,

Steve O

Page 1
----------------------------------------------------------------------------------------------

 

<telerik:radgrid id="RadGrid1"

 

 

runat="server"

 

 

AllowAutomaticDeletes="True"

 

 

AllowSorting="True"

 

 

AllowPaging="True"

 

 

PagerStyle-HorizontalAlign="Center"

 

 

AllowMultiRowEdit="false"

 

 

AllowMultiRowSelection="false"

 

 

OnItemDataBound="RadGrid1_ItemDataBound"

 

 

OnItemUpdated="RadGrid1_ItemUpdated"

 

 

OnUpdateCommand="RadGrid1_ItemUpdate"

 

 

OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged"

 

 

OnNeedDataSource="RadGrid1_NeedDataSource"

 

 

GridLines="None">

 

 

 

<ClientSettings EnablePostBackOnRowClick="true" >

 

 

<Selecting AllowRowSelect="True" />

 

 

<Scrolling AllowScroll="True" UseStaticHeaders="True" />

 

 

</ClientSettings>

 

 

<MasterTableView runat="server"

 

 

DataKeyNames="CaseNbr, Article, Item"

 

 

AllowSorting="true"

 

 

CommandItemDisplay="Top"

 

 

AutoGenerateColumns="false">

 

 

 

<EditFormSettings EditFormType="Template">

 

 

<EditColumn UniqueName="EditColumn"></EditColumn>

 

 

<FormTemplate>

 

 

<table>

 

 

<tr>

 

 

</tr>

 

 

</table>

 

 

</FormTemplate>

 

 

</EditFormSettings>

 

 

<CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="true" />

 

 

 

<Columns>

 

 

 

<telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" HeaderText="Select" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="20px"></telerik:GridClientSelectColumn>

 

 

<telerik:GridBoundColumn DataField="RecCode" UniqueName="RecCode" Visible="false"></telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="CaseNbr" HeaderText="Case Nbr" HeaderStyle-Font-Bold="true" HeaderStyle-Wrap="true" UniqueName="CaseNbr" SortExpression="CaseNbr" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Vic1" HeaderText="Victim" HeaderStyle-Font-Bold="true" HeaderStyle-Wrap="true" UniqueName="Vic1" SortExpression="Vic1" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Item" HeaderText="Item" HeaderStyle-Font-Bold="true" UniqueName="Item" SortExpression="Item" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ></telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Article" HeaderText="Art" HeaderStyle-Font-Bold="true" UniqueName="Article" SortExpression="Article" HeaderStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="ArticleType" HeaderText="Art Type" HeaderStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ItemStyle-Wrap="true" HeaderStyle-Wrap="true" UniqueName="ArticleType" SortExpression="ArticleType" Visible="true"></telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="ArticleName" HeaderText="Art Name" HeaderStyle-Font-Bold="true" HeaderStyle-Wrap="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ItemStyle-Wrap="true" UniqueName="ArticleName" SortExpression="ArticleName" Visible="true" ></telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="SerialNbr" HeaderText="Serial #" HeaderStyle-Font-Bold="true" HeaderStyle-Wrap="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ItemStyle-Wrap="true" UniqueName="SerialNbr" SortExpression="SerialNbr" Visible="true"></telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Location" HeaderText="Loc" HeaderStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ItemStyle-Wrap="true" UniqueName="Location" SortExpression="Location"></telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="NextAct" HeaderText="NextAct" HeaderStyle-Font-Bold="true" HeaderStyle-Wrap="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ItemStyle-Wrap="true" UniqueName="NextAct" SortExpression="NextAct"></telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="NextActDate" HeaderText="Next Date" HeaderStyle-Font-Bold="true" HeaderStyle-Wrap="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ItemStyle-Wrap="true" UniqueName="NextActDate" SortExpression="NextActDate"></telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="FinalAct" HeaderText="FinalAct" HeaderStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ItemStyle-Wrap="true" UniqueName="FinalAct" SortExpression="FinalAct" ItemStyle-Width="50px"></telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="FinalActDate" HeaderText="Final Date" HeaderStyle-Font-Bold="true" HeaderStyle-Wrap="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ItemStyle-Wrap="true" UniqueName="FinalActDate" SortExpression="FinalActDate"> </telerik:GridBoundColumn>

 

 

 

</Columns>

 

 

<EditFormSettings>

 

 

<EditColumn UniqueName="EditCommandColumn" ButtonType="ImageButton"

 

 

CancelImageUrl="~/Images/filterCancel.png"

 

 

UpdateImageUrl="~/Images/selecttag.png"

 

 

InsertImageUrl="~/Images/selecttag.png">

 

 

</EditColumn>

 

 

 

<FormTemplate>

 

 

<table>

 

 

<tr>

 

 

</tr>

 

 

</table>

 

 

</FormTemplate>

 

 

</EditFormSettings>

 

 

<CommandItemTemplate>

 

 

 

<table>

 

 

 

<tr>

 

 

<td style="width:30%">&nbsp;</td>

 

 

 

<td>

 

 

<asp:LinkButton ID="LinkButton8" OnClick="Gang_Update_Click" Text="Gang Update" Runat="server" Font-Size="Large" ForeColor="DarkRed" Font-Underline="true" Font-Bold="true" ToolTip="Update Selected Item"></asp:LinkButton>

 

 

</td>

 

 

 

<td style="width:28%; text-align:right;">

 

 

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/Refresh.gif" CommandName="Rebind" ToolTip="Refresh" />

 

 

</td>

 

 

<td style="width:1%; text-align:right; vertical-align:top">

 

 

<asp:LinkButton ID="LinkButton1" Text="Refresh" CommandName="Rebind" Runat="server"></asp:LinkButton>

 

 

</td>

 

 

<td style="width:1%">&nbsp;</td>

 

 

 

</tr>

 

 

 

</table>

 

 

 

</CommandItemTemplate>

 

 

 

</MasterTableView>

 

 

 

<ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">

 

 

<Scrolling AllowScroll="True" UseStaticHeaders="True" />

 

 

<Selecting AllowRowSelect="True" />

 

 

</ClientSettings>

 

 

<FilterMenu EnableImageSprites="False">

 

 

</FilterMenu>

 

 

</telerik:radgrid>

 


---------------------------------------------------------------------------------------------------------------

namespace

 

Evidence.Forms

 

{

 

public partial class Results : System.Web.UI.Page

 

{

 

private string gridMessage = null;

 

 

string status = "";

 

 

string qType = "";

 

 

string casenbr = "";

 

 

string item = "";

 

 

string art = "";

 

 

string article = "";

 

 

string name = "";

 

 

string arttype = "";

 

 

string artname = "";

 

 

string sernbr = "";

 

 

string fdate;

 

 

string tdate;

 

 

string uName = "";

 

 

//DateTime fdate;

 

 

//DateTime tdate;

 

 

static string prevPage = String.Empty;

 

 

protected void Page_Load(object sender, EventArgs e)

 

{

 

if (!Page.IsPostBack)

 

{

 

string userName = HttpContext.Current.User.Identity.Name;

 

Session[

"Name"] = userName.Substring(userName.LastIndexOf('\\') + 1);

 

uName = userName.Substring(userName.LastIndexOf(

'\\') + 1);

 

 

Evidence_UserCollection records = new Evidence_UserCollection().Where("UserName", uName).Load();

 

Session[

"Access"] = "";

 

 

RadMenu menu = (RadMenu)Master.FindControl("RadMenu1");

 

 

RadMenuItem admin = menu.FindItemByText("Administration");

 

 

RadMenuItem delete = menu.FindItemByText("Delete");

 

 

//admin = menu.FindItemByText("Access");

 

 

// configure access prive based on role assigned

 

 

if (records.Count() > 0)

 

{

 

//GridItem cmdItem = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];

 

 

Evidence_User record = records.First();

 

 

switch (record.RoleId)

 

{

 

case 1:

 

admin.Visible =

true;

 

 

//cmdItem.FindControl("LinkButton2").Visible = true;

 

 

//cmdItem.FindControl("LinkButton3").Visible = true;

 

 

break;

 

 

case 2:

 

admin.Visible =

false;

 

 

//cmdItem.FindControl("LinkButton2").Visible = false;

 

 

//cmdItem.FindControl("LinkButton3").Visible = false;

 

 

break;

 

 

default:

 

admin.Visible =

false;

 

 

//cmdItem.FindControl("LinkButton2").Visible = false;

 

 

//cmdItem.FindControl("LinkButton3").Visible = false;

 

 

break;

 

}

}

 

Evidence_UserCollection users = new Evidence_UserCollection().Where("UserName", uName).Load();

 

Session[

"Access"] = "";

 

 

if (users.Count() > 0)

 

{

RadGrid1.MasterTableView.Columns[11].Visible =

true;

 

}

 

else

 

{

RadGrid1.MasterTableView.Columns[11].Visible =

false;

 

}

 

// first retrieve the query type and values and run the stored proc

 

 

//status = Request.QueryString["status"].ToUpper();

 

qType = Request.QueryString[

"qType"].ToUpper();

 

name = Request.QueryString[

"name"].ToUpper();

 

casenbr = Request.QueryString[

"casenbr"].ToUpper();

 

item = Request.QueryString[

"item"].ToUpper();

 

art = Request.QueryString[

"art"].ToUpper();

 

arttype = Request.QueryString[

"arttype"].ToUpper();

 

artname = Request.QueryString[

"artname"].ToUpper();

 

sernbr = Request.QueryString[

"sernbr"].ToUpper();

 

 

if (string.IsNullOrEmpty(name))

 

{

name =

null;

 

}

 

if (string.IsNullOrEmpty(casenbr))

 

{

casenbr =

null;

 

}

 

if (string.IsNullOrEmpty(item))

 

{

item =

null;

 

}

 

if (string.IsNullOrEmpty(art))

 

{

art =

null;

 

}

 

if (string.IsNullOrEmpty(arttype))

 

{

arttype =

null;

 

}

 

if (string.IsNullOrEmpty(artname))

 

{

artname =

null;

 

}

 

if (string.IsNullOrEmpty(sernbr))

 

{

sernbr =

null;

 

}

fdate = Request.QueryString[

"fDate"];

 

tdate = Request.QueryString[

"tDate"];

 

Session[

"status"] = status;

 

Session[

"qtype"] = qType;

 

Session[

"name"] = name;

 

Session[

"casenbr"] = casenbr;

 

Session[

"item"] = item;

 

Session[

"art"] = art;

 

Session[

"arttype"] = arttype;

 

Session[

"artname"] = artname;

 

Session[

"sernbr"] = sernbr;

 

Session[

"fdate"] = fdate;

 

Session[

"tdate"] = tdate;

 

 

if (!string.IsNullOrEmpty(fdate))

 

{

fdate = fdate.Substring(1, fdate.IndexOf(

" ") - 1);

 

}

 

if (!string.IsNullOrEmpty(tdate))

 

{

tdate = tdate.Substring(1, tdate.IndexOf(

" ") - 1);

 

}

 

if (RadGrid1.Items.Count > 0)

 

{

RadGrid1.DataBind();

}

}

}


 

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)

 

{

 

//status = Request.QueryString["status"].ToUpper();

 

qType = Request.QueryString[

"qType"].ToUpper();

 

name = Request.QueryString[

"name"].ToUpper();

 

casenbr = Request.QueryString[

"casenbr"].ToUpper();

 

item = Request.QueryString[

"item"].ToUpper();

 

art = Request.QueryString[

"art"].ToUpper();

 

arttype = Request.QueryString[

"arttype"].ToUpper();

 

artname = Request.QueryString[

"artname"].ToUpper();

 

sernbr = Request.QueryString[

"sernbr"].ToUpper();

 

fdate = Session[

"fdate"].ToString();

 

tdate = Session[

"tdate"].ToString();

 

 

DataSet ds = SPs.Get_Evidence(qType, name, casenbr, item, art, arttype, artname, sernbr, fdate, tdate, status).GetDataSet();

 

RadGrid1.VirtualItemCount = ds.Tables[0].Rows.Count;

RadGrid1.DataSource = ds;

}

12 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Jan 2012, 05:20 AM
Hello,

One suggestion is you can disable the paging and then rebind the grid.
C#:
RadGrid1.AllowPaging = false;
RadGrid1.Rebind();
 foreach (GridDataItem item in RadGrid1.Items)
  {
  //your code
  }
RadGrid1.AllowPaging = true;
RadGrid1.Rebind();

-Shinu.
0
JSON
Top achievements
Rank 1
answered on 18 Jan 2012, 05:31 PM
No, The paging is part of the required process. I don't understand what you mean.

The user selects a record from the grid list and navigates to an edit page, then returns to the grid page.
0
Tsvetina
Telerik team
answered on 20 Jan 2012, 10:00 AM
Hello,

In a case where you actually reload the grid page, NeedDataSource should fire and reload the records in grid. So, can you please elaborate a little more on how exactly you navigate between the regular view and edit page? Is it browser navigation or through some implemented navigation in your site?

Kind regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Vamsi Kamal
Top achievements
Rank 1
answered on 02 May 2012, 01:04 PM
Telerik Team,

I am facing a problem using RadGrid. i.e,
When the RadGrid doesn't have any data, Under the post backs, it is showing a duplicate page navigator on top of the RadGrip.
Could you please provide any suggestions to fix this issue.
0
Shinu
Top achievements
Rank 2
answered on 08 May 2012, 03:27 PM
Hi,

I am not sure about your requirement . Can you please elaborate your scenario.

Thanks,
Shinu.
0
Vamsi Kamal
Top achievements
Rank 1
answered on 09 May 2012, 06:16 AM
Hi Shinu,

Here is my problem description.
In my page I have two drop down lists, two rad grids and two buttons.
Ex: drpdwn1, radgrd1, btn1 and drpdwn2, radgrd2, btn2
When I select an item from drpdwn1, it binds data to radgrd1, If I select an item from drpdwn2 it binds radgrd2.

Actual Problem:
When I select drpdwn1 it fills data to radgrd1.
Then I click on any of the buttons, then radgrd2 is showing two page navigators. (In this scenario radgrd2 doesn't have data)
It happens only when the radgrid has no data. If it contains data, it is working fine.

Can you provide me any suggestion or solution for this.
PFA.
0
Shinu
Top achievements
Rank 2
answered on 09 May 2012, 08:26 AM
Hello Vamsi,

I also tried the same scenario. I was able to replicate the issue on setting the PagerStyle properties. Please make sure that you are not setting  AlwaysVisible as true and Position as TopAndBottom when there are no records in the grid. Hope this helps.

Thanks,
Shinu.
0
Vamsi Kamal
Top achievements
Rank 1
answered on 09 May 2012, 08:49 AM
Hi Shinu,

Thanks for your quick reply.
I tried the same. But setting AlwaysVisible to false is gives below issue.

If the number of records(or items) or less than the page size selected, then page navigator completely disappearing.
So this is not a perfect solution for me...
0
Tsvetina
Telerik team
answered on 09 May 2012, 03:00 PM
Hi Vamsi,

Can you provide code that we can use to replicate the problem locally, so that we can inspect it and see what causes it and how it can be fixed?

All the best,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Shinu
Top achievements
Rank 2
answered on 10 May 2012, 05:43 AM
Hi Vamsi,

For your desired functionality you can set the PagerStyle property 'AlwaysVisible' as true. And depending on the condition(If RadGrid has no records) you can set the same property to false in the PreRender event. Please take a look into the code snippet I tried.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    int rowcount = RadGrid1.MasterTableView.Items.Count;
    if (rowcount == 0)
    {
        RadGrid1.PagerStyle.AlwaysVisible = false;
    }
}

Thanks,
Shinu.
0
Vamsi Kamal
Top achievements
Rank 1
answered on 11 May 2012, 03:02 PM
Hi Shinu,

I already tried setting PagerStyle.AlwaysVisible = true and false based on the count of columns in the MasterTableView.
But there is no change in the output. Still the problem is existing.
0
Shinu
Top achievements
Rank 2
answered on 14 May 2012, 06:42 AM
Hi Vamsi,

Unfortunately i couldn't replicate the issue. Can you please provide your complete code for further assistance.

Thanks,
Shinu.
Tags
Grid
Asked by
JSON
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
JSON
Top achievements
Rank 1
Tsvetina
Telerik team
Vamsi Kamal
Top achievements
Rank 1
Share this question
or