Edit first column of GridView - asp.net

I've got very dynamic GridView and I need to allow to user to edit first column of it. After he edit first column of grid it must be updated on DataBase.
Is there any ways to handle it ?
My only idea is to put some changeable element to first cell of each Row so it must be able to set / get my values for each row but can't find yet any examples of it ...
Additional info :
GridView takes data from Object data source and all columns are dynamic (yes, maybe except first, but I add it in dynamic way) and load complete DataTable... \
Currently Using jQuery+Ajax methode on dynamic button but can't disable button's PostBack so with a PostBack it just disappears and dont make the event it must to make...

Since you have dymanic columns, for each column, specify the read-only property (If a column is read-only, it may only be looked at, and not edited when in the GridView's Edit-Mode).
So, the first column of would be readonly="false" (or omit it entirely) and the other columns read-only="true".

Related

Changing the tooltip dynamically for each record

In forms I have a block that contains name of tables.
The column is narrow so I want to add a tooltip that contains the value for each row.
I tried to put this code in post_query
:set_item_property('block1.value',tooltip_text, :block1.value);
but the tooltip always contains the last row's value and shows
it for all the rows. What could be the problem here?
set_item_instance_property is the ideal way to affect a column for just specific rows of data. But, tooltip_text is not available for setting via set_item_instance_property.
What you could do, though, is put your call to set_item_property into a when-new-record-instance trigger on the block. That way it should change the tooltip each time a new record becomes the focus.

How to pass dummy gridview column in <ASP:HyperLinkField> URL as querystring

I am facing problem in passing a dummy column's value in URL of <asp:HyperLinkField>.
My first column in gridview contains value from <%#Container.DataItemIndex+1> which gridview is populating however on click on my 2nd column which is a hyperlink field i want to pass value from 1st columns generated by <%#Container.DataItemIndex+1>.
So the problem here i am facing is how to pass a value as querystring which is not getting populated from database however is available as column in gridview.
Thanks in advance,
Can you paste the code so i can detect the problem and tell you what to do. Cos one thing you need to understand is the gridview tend itemize cell as zero index. So if your intention is to get say the ID of a table to a linkfieldbutton, i will advice you to use LinkButton.
Assuming I understood your question:
Have you tried binding column 2 to the same field (DataField) column1 is so you can use the (same) data any way you want.
Alternatively, perhaps you can (already) use column1 for the same purpose (re: display and link)?
Hth....

How to Display a DataGrid with Insert Mode without any pre-filled data?

How to display the datagrid in insert mode without any data in it.
The GridView is empty and contains only one header.
I want to insert the data in the GridView when the application is running.
What you could do is using an empty Binding Source to a List which would enable you to add new Rows.
Check out some samples of how to use the Binding Source here
Please have a look at these 2 examples:
Insert rows with a GridView
Adding Insert Capabilities to the GridView
I don't think the datagrid will be rendered if its data source is empty. To work around this problem you can give it a data source with only one item that is regarded as empty (for example a data table with one row where all columns have empty values). You can then check for this special case in your program logic.

Get Changed Rows of GridView ASP.Net

How Can I find all the rows that has been changed in gridview. I can not use Ajax in any form
First get the contents of your grid before it was changed (such as caching the results of the original gridview datasource binding). Then go through the dataset/datatable/however you want to store it, and compare the contents with the current rows of the gridview.
There's no real efficient way to do this, no method like GridView.GetAllChangedRows(). So, what you might do instead is keep a behind the scenes List that you add to each time a row is modified (use the RowUpdated method), then clear this list when needed.
It depends upon how many columns you want to edit in a row.
If you have only one editable column in a row then you can associate a javascript method with that control which you want to modify and in that method you can get a rowid which you can save in another hidden field and in server side you can get all rows whose ids are stored in hidden field.
If you have whole row editable in that case the best approach I think you should save the original data source somewhere and also set a javascript method with rowclick event to get rowid which user selects. Then when user clicks on submit button get all rows whose row ids are stored in hidden field then compare those with same rowid in datasource. This is the best approach from my point of you.
Let me give you an example, suppose there are 1000 rows in a grid and user clicks on only 180 rows. In that case we will compare only 180 rows and wont compare rest of the rows.
Please let me know if somebody has better idea then this.

ASP.NET Datagrid - hiding a specific row/column

I am using a Datagrid with several columns of data (call it myDG) and one of these columns is a DateTime bound to a datasource. Its value is dependent on a "job" object completing a job and assigning the date time value. Since this normally takes up to a minute the value is left unassigned at the beginning.
The column's asp.net definition is:
<asp:boundcolumn
DataField="CompletedDate"
HeaderText="Date Completed"
DataFormatString="{0:dd-MMM-yyyy <br> hh:mm:ss tt}" />
So the functionality works fine when the "job" has completed and it sets the time. But before that, while the row is being displayed, it shows as
01-Jan-0001
12:00:00 AM
I am wanting to hide this and determined that the best way would be to mask that particular row and column with a blank, or override the value temporarily. I am having problems doing this and finding a way to access that specific row and column.
It is the [3] column of the datagrid and always in the first row (since new rows are added at the top).
Is there a way to directly access this cell and temporarily 'hide' its contents, or mask them? Ideally it would be great if there was a way to blank out all rows that had a value equal to this in their column, but a way to manipulate the specific cell would work as well.
-thanks in advance!
I would probably hook OnItemDataBound, check the value, and replace/reformat if required.
I asked a similar question about hiding columns here.
I had to use the RowCreated event to hide certain columns from the user (PK columns) and this may help you out as well (especially with hiding databound columns).
I have done similar things in the past and here is what I have done.
Bind the data to a column that is not visible at all. Add a visible column for the data you wish to display. At the time you populate your grid, loop through the records and for any that have a value that isn't 01-Jan-0001 12:00:00 AM, set your visible row to that value. If it does equal 01-Jan-0001 12:00:00 AM, then set the value of your visible row to an empty string or some value of your choice. (You could even set the text color to the same as the background color so it wouldn't appear to the user)

Resources