Programmatically selecting a row on a non visible page

Answered (Not Verified) This post has 0 verified answers and 11 replies

Top 500 Contributor
Posts: 18
netdeviq Posted: Fri Dec 4, 2009 @ 2:53 AM

Hi,

I have a datagrid containing several pages of rows. On server-side I loop through the datagrid-rows to find a certain item (row) that I select using grid.select(item). Since the selected row is probably on another grid-page than the grid-page that is curently presented to the user how can I find the page that contains the selected row and how can I change to that page from server side so the user sees the selected row?


Thanks in advance,
Hans

All Replies

Top 10 Contributor
Posts: 6,424
Answered (Not Verified) hwan Posted: Fri Dec 4, 2009 @ 8:25 AM

Get the Index of the Item from its DataKeyField (or whatever identifier you're using), then do something like:

 

int index = Grid1.Items.IndexOf("ID", theSelectedItemId);
if (index >= 0)
{
  // Page to selected item
Grid1.CurrentPageIndex = Math.Floor((double)(index / Grid1.PageSize));
Grid1.DataBind();
}

 

http://www.componentart.com/community/forums/p/37467/37467.aspx#37467

Top 500 Contributor
Posts: 18
netdeviq Posted: Sat Dec 5, 2009 @ 1:53 AM
Hi,

Thanks for the answer. I think I could have found it myself if I thought a bit more and looked a bit further, but I had found a lot of answers that day very quickly thanks to the straightforward properties and methods of the datagrid and this one didn't appear to me quickly enough I guess.

I'm struck by the flexibility of this datagrid.
It's a well thought out control and a lot more intuitive that its Microsoft counterpart.

Regards,
Hans
Not Ranked
Posts: 4
ikabott Posted: Wed Jul 27, 2011 @ 4:33 AM
Hi,

I have server side paging and when I do:

int index = Grid1.Items.IndexOf("ID", theSelectedItemId);

I get a -1 back, as Item only contains those the items of the current page.

Any idea?

Oscar
Top 10 Contributor
Posts: 694
ajay Posted: Fri Jul 29, 2011 @ 7:15 AM

Hello,

 

Please find the attached sample application to programmatically select a row of grid.

 

Hope it will help you.

 

Thank you.

 

Ajay Mishra

Top 500 Contributor
Posts: 23
prometeus Posted: Tue Jan 17, 2012 @ 6:24 AM
Hello,

I think, This sample works only if grid mode is client. How can we do this for callback mode?
Thank you.
Top 10 Contributor
Posts: 694
ajay Posted: Tue Jan 17, 2012 @ 10:19 AM

Hello,

 

Thanks for getting back to me.

 

Callback’s behavior is not applicable to Grid in Client RunningMode. The problem is that Grid Callback only load one PageSize of rows, whereas the Grid in Client RunningMode expects to have the entire set of rows loaded on the client at all times. So, after the first callback you run into issues as you have described.

 

Unfortunately you cannot get the selected row dynamically with Callback Grid. Workaround for the same is to use Client mode Grid.

 

Thank you.

 

Ajay Mishra

Top 500 Contributor
Posts: 19
Anushka11 Posted: Fri Feb 3, 2012 @ 5:22 AM
Hello Sir,

I have a grid and in a grid there is only 3 rows i need to create a drilldown on each row .How do i get the index or no of selected row in ItemCommand event. (Means i want, user has selected either 1st row or 2nd row or 3rd row coz on that basis i need to fetch the another data).

One more thing i want different color of my rows for eg 1st row color should be red, 2nd row color green and 3rd row color should be yellow.

Please reply soon.
Thanks



Top 10 Contributor
Posts: 694
ajay Posted: Fri Feb 3, 2012 @ 6:51 AM

Hello,

 

Thanks for getting back to me.

 

Please use the following code to get the index of the selected row in ItemCommand event of Grid.

 

  

 void DataGrid1_ItemCommand(object sender, ComponentArt.Web.UI.GridItemCommandEventArgs e)

  {

      ComponentArt.Web.UI.GridItemCollection selectedItems = default(ComponentArt.Web.UI.GridItemCollection);

      selectedItems = this.Grid1.SelectedItems;

      if (selectedItems.Count > 0)

      {
          //do something to the selecteditems.

          int selectedIndex = Grid1.Items.IndexOf(selectedItems[0]);

          //Response.Write(selectedIndex.ToString());

           System.Windows.Forms.MessageBox.Show(selectedIndex.ToString());

      }
  }

 

Further you can use Itemcontent event of Grid which expose an index like property. Perhaps you can use your DataKeyField value and check that against the rowset and change its formatting. Something like:

 

  // Find the item with ID 9031.

  int index = Grid1.Items.IndexOf("ID", 9031);

 

Or you can use the logic given in conditional formatting for each row. You may refer the following inbuilt sample application for the same:

 

http://aspnetajax.componentart.com/control-specific/datagrid/rows_and_columns/conditional_formatting/WebForm1.aspx

           

Please refer the following forum links to get the workaround for the same:

 

http://www.componentart.com/community/forums/p/45673/45673.aspx#45673

           

http://www.componentart.com/community/forums/p/26730/26747.aspx#26747

 

Hope it will help you.   

 

Thank you.

 

Ajay Mishra

Top 500 Contributor
Posts: 19
Anushka11 Posted: Sat Feb 4, 2012 @ 2:25 AM
Thanks for the quick respone sir...

It's not working for me. Actually my requirement is:
 I am explaining my problem here:

My grid look like this

Amount     Unit     Percentage

7890         60        35%
65667       32         40%

7676       54           89%

In my grid first row shows the value whose saledate>getdate()-3  and this row color should be red.

second row of a grid shows values of saledate between getdate and getdate()+3 and this row color should be yellow.

third row of a grid shows values of shipdate >= getdate  and this row color should be orange.

Sometime happens that in my grid shows either 2 or 1 or 3 rows according to data in database but not morethan 3 coz i used aggreagate function "SUM".
Now i need to drill down on each row which shows on grid and that will load the another grid which shows the details of  that perticular columns(amount,percentage,customer,location etc etc).

For eg: If i drill down on red color row then my data should be like

Cust  Loc   Date  Amount   Percentage  
 whose condition is  saledate>getdate()-3  as i described above.

If i drill down on green color row then my data should be like

Cust  Loc   Date  Amount   Percentage  
 whose condition is  saledate between getdate and getdate()+3  as i described above.

that's why i need a row no which row no i have selected..


Plese help me  it's urgent.

Top 500 Contributor
Posts: 19
Anushka11 Posted: Sat Feb 4, 2012 @ 2:40 AM
one more thing,
 i want from you is ,  how can i set the specific colors for rows...and how can i able to know which  color row user has selected

In my first  grid for first row query is like this: Select SUM(AMOUNT) as amount ,SUM(units) unit, SUM(Pct) as pct where saledate > getdate()-3 from orders;
I cant use one more parameter like saledate in select coz then it will fetch more than one row. thats why i can't use  conditional formating like this:

                ComponentArt.Web.UI.GridConditionalFormat gcfg1 = new ComponentArt.Web.UI.GridConditionalFormat();
                gcfg1.ClientFilter = ("DataItem.GetMember('saledate').Value " == getdate());

                gcfg1.RowCssClass = "greenrow";
                gcfg1.SelectedHoverRowCssClass = "greenrow";
                Grid1.Levels[0].ConditionalFormats.Add(gcfg1);

gcfg1.ClientFilter = ("DataItem.GetMember('saledate').Value " == getdate());
this line will not work for me for the color of row.

Please help.
Top 500 Contributor
Posts: 19
Anushka11 Posted: Sun Feb 5, 2012 @ 10:16 PM
It's been 48 hours i posted my query..But didn't get any response from your side.

Please anyone reply to my query..
Page 1 of 1 (12 items)