Jump to content
Software FX Community

Selecting a record after sorting the grid.


KodgireVijay
 Share

Recommended Posts

Hi,

 In my application, I need the first record in the grid to be selected by default after sorting is done on the grid. Please help.

Following is the code where I am binding the dataview to the grid :

 protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack){Grid.DataBind();}}protected void Grid_DataBinding(object sender, EventArgs e)

{

DataSet dsOPS = call to get the dataset.DataView vwOPS = dsOPS.Tables[0].DefaultView;

Grid.DataSource = vwOPS;

}Sorting is enabled.

<

Sorting Enabled="True" UIBehavior="SingleField" />

 Please let me know how i can select the first record immediately after the sorting is done.

Link to comment
Share on other sites

Hi, now I am able to select the first row in the grid after sorting. I am doing it in the onrendering event of the grid. I am trying to enable the btnButton everytime the first record gets selected. Also, disable it when any other record (except first) is selected.

public void grid_rendering(object sender, EventArgs e)

{

if (Grid1.SelectedItems.Count == 0)

{Grid1.Items[0].Selected =

true;}

if (Grid1.Items[0].Selected)

{btnButton.Enabled =

true;}

else{btnButton.Enabled = true;}

}

When the screen loads first time, the first record gets selected by default and the btnButton also gets enabled. Then I select any other record from the grid, and the btnButton gets disabled. This is exactly what we want. But now when I sort the grid, the first row gets selected in the grid but the btnButton does not get enabled.

The selection property is :

<

Selection ChangeAction="Postback">

Please let me know if I am missing to set a property.

 Thanks.

Link to comment
Share on other sites

Hi,

Unfortunately that's an outstanding bug.  The problem there is that since sorting is done via callback and not postback, the button's html is not updated.  This will be fixed in our next service pack.  If it's urgent I might be able to prepare a hotfix for you.

Once it's fixed, all commands that affect the selected item, such as sorting, paging, and filtering, will use the postback.  Additionally in the future we will provide a simple way for you to use callbacks and still update outside controls, such as the button in question.

Also, you should set the selected item in the PreRender event as opposed to the Rendering event because the server-side viewstate for that item will not be saved and upon postback from some outside control (like that button), the item will no longer be marked as selected. 

Let me know how urgent it is.  Thanks so much for using Grid FX!

Link to comment
Share on other sites

Thanks for your reply. I also have one more problem related to sorting the grid :

 I am able to select the first row after sorting the grid. I am doing that in the grid rendering event :

 
public void grid_rendering(object sender, EventArgs e)

{

if (Grid1.SelectedItems.Count == 0)

{Grid1.Items[0].Selected = true;}

if (Grid1.Items[0].Selected)

{btnButton.Enabled = true;}

else{btnButton.Enabled = true;}

}

I am trying to enable disabled the buttons based on the selected row value.
 
When the Selection ChangeAction="Postback" :  When the screen loads first time, the first record gets selected by default and the btnButton also gets enabled. Then I select any other record from the grid, and the btnButton gets disabled. This is exactly what we want. But now when I sort the grid, the first row gets selected in the grid but the btnButton does not get enabled.

When the Selection ChangeAction="ClientOnly" : Now I am doing the following steps :

  • When the grid loads, assume that the fifth row contains value "A" in a column.
  • Sort the grid
  • Select the fifth row in the grid after sorting. (Assume the value of a column in that row contains "B")
  • Click on a button to check the values of the selected row.
  • The values of the selected row should the "B". But while accessing through code, it is showing "A". As a result enabling and disabling of buttons is not happening as expected (as actual values and displayed values in the row are different).
Please let us know if we need to change any settings.
 
Thanks for your help.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...