开发者

GridView Initial Editing mode?

I am writing a web application that is used for tracking and entering some everyday user data... Every day I need to enter some data for multiple users manually...

I will choose the date with the calendar, and for that date I will get DB values assigned for all users on chosen date...If there are some entries in database for that date i will display it in gridview...

Here is the look of gridview for chosen date...

USERS   DATA
------------
User1   Data1
User2   Data2
User3   Data3

But, if I choose the date for which there are no entries in DB, I would like to display the gridview containg User names in each row, but I want the second column (DATA field) to be initially editable for ALL rows (the whole second column should contain textboxes for inserting values, not only selected row as in standard editable gridview mode) allowing inserting of wanted values...

I want it to look something like this

USERS   DATA
----------------
User1   TextBox
User2   TextBox
User3   TextBox

My idea is to get Users list from DB and create a datatable with first column containg returned user names, and second column empty... This datatable will be datasource for gridview in which I am going to disable editing mode, and in normal (displaying) mode I am going to have TemplateField containg of textboxes bound to that datatable in second column, and labels displaying usernames in first column... When entering all values there will be SAVE button who is calling a method that will read entered values from datatable and save it to database...

Is there a better way to implement this functionality? If Templatefield textboxes are bound to datatable (as gridview datasource) textboxes entered values are going to be accessible from datable object, but Save button click causes postback, and I don't know how to preserve datatable state? Is there a better way to g开发者_如何学JAVAet wanted gridview with whole second column availibe for inserting new values?

Thank you in advance for your help & time!


Try this

http://www.highoncoding.com/Articles/219_GridView_All_Rows_in_Edit_Mode.aspx

http://csharpdotnetfreak.blogspot.com/2009/05/edit-multiple-records-gridview-checkbox.html


I would retrieve the full dataset using a left join in the database, and if there is no entry for a user, that user will be returned with a blank value. Something like this:

select users.user, isnull(entries.entry,'') from users left join entries on users.userid = entries.userid

I think you can override the OnDataBinding (or OnDataBound) method to check and see if the second column is empty, and place the field in edit mode if it is. This way, if some users have entries but some don't, only the users with no entry will be in edit mode. Any user with an entry will be in display mode. There is a sample for this at http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdatabound.aspx.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜