开发者

How to change a status of a button in gridview

I am working on a job portal site where user can enter multiple profiles.

I am showing all profiles in a gridview. My requirement is now that there should be a status link with his all profiles (it is in bit).

Example: This is my gridview:

jobseekerid | Profileid | status

     1           2        Active
     1           3        DeActive
     1           4        DeActive
            ....
            ....

From all of this only one profile can be active. So when the user clicks on any inactive profile, it will become active and then all remaining profile will become inactive. The condition is that at a time only one profile can be active. (When he make his one profile active, the remaining o开发者_StackOverflow社区nes will become inactive automatically.)

Now the Problem is, I am not able to make all the remaining profiles inactive when the user makes a profile active in the gridview.

How can I do this?


This is a common problem, and is usually solved by retaining the original dataset that you populated the gridview with. So, in your case, you should stored the dataset (or a list of profiles - whatever dataset you used to populate gridview) in a viewstate (given it is not too big, otherwise the page will load slow). Then, when you populate your gridview, you need to assign a profile ID to each click event, so you know which one got clicked. You then need to loop over the dataset that you saved in your viewstate, and update all of them (except the one that just got clicked) to inactive. The loop is not as cludgy as it sounds... with sql server 2005 and 2008 you have a new datatype called 'table', so you can pass all the other profileIDs in a one swoop to the DB to update them all to inactive.


Upon an update, loop through the table rows of the Gridview and change the values accordingly, if that's sufficient enough to update the record in the backend. If there is a value associated with it, you could hold that value in a hidden field and change the value in the hidden field as well.

If these changes are going to happen on the fly (i.e. you are updating the database upon a change), you could set a hidden field as a postback trigger and eval() it when you've clicked on whatever button is saving your updated record with the updated status. This would cause the RowCommand to fire, where you could loop through each record and update accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜