I am populating a telerik:RadGrid from a DataTable. Each of the DataRows in the DataTable has a "readonly" column with a value of true or false.
The grid currently has a GridEditCommand column, and a GridButtonColumn that triggers the "Delete" command.
What I need is for rows that display records for which "readonly" is true to be read-only. I need the icon in the GridEditCommand column to be different, and for clicking it to bring up a view-details form, instead of an edit form. And I need the link in the "Delete" GridButtonColumn to be absent.
It looks like it'd be pretty straightforward to create a table that doesn't allow the user to edit or to delete records, but I need to be able to have some rows editable and some not.
Where should I start?
This is possible; I'd recommend on the left, the image be a command button, and you trigger the right action depending on the selection you make in itemcommand event. To change the icon, you'd need to tap into the rowdatabound event and programmably change it. Now for showing view details, I don't know if the Telerik grid has something built-in for the read-only view; this may have to be programmably done with a control outside of the grid.
HTH.
Related
I have a aspx page consisting of a calendar button and a textbox.When we click calendar button then a calendar appears and the date which i select on calendar appears in textbox. Now what i want is to load the data from database according to the date selected and allow the user to edit it.And also i want to enable user to add rows at runtime. Do i need to create grid view at runtime?? Can somebody point me in a direction??
You don't need to create the gridview at runtime. You can define the gridview in the markup without having any data initially. You can set the calendar to autopostback and on the server side, capture the new date selected, grab the data based on that date and bind it to your gridview.
As far as editing the data, Gridviews already provide support for this and the amount of code that you need to write largely depends on how the datasource for the gridview is set up. If you use a SQLdatasource with the appropriate settings you practically don't have to write a single line of code besides the markup (Google: Gridview SQLdatasurce editing ASP.net).
I want to do something really simple, I just can't seem to find the EnableClientAddRow property, so I can set it to true. I have a standard GridView control on a web form. I want a button to appear on the web form. When the user clicks the button, an empty row is added to the GridView UI, so the user can enter data in the appropriate fields. The row will of course, have a "Save" button of some type in one of the columns.
I know this functionality must be in the GridView somewhere, I just can't find it. I did find some odd hacks that try to manually implement this. I'm not really interested in footer manipulations or binding tricks, just the standard add row method.
EDIT:
It appears the GridView does not support adding a row as a first-order operation. This appears to be a serious design flaw.
I typically add a new record to the underlying data source as a part of the "add record" button click action. I then re-bind the view in order to show the blank row.
The new record is typically a DataRow if the GridView is bound to a DataTable, or an object if the GridView is bound to a collection of a particular type. Not sure if that is what you consider a binding trick from your question, but it works well and is quite easy to implement.
Edit - more detail to describe the process:
Add the row to the data source, set the EditItemIndex to the newly added row in order for the row to enter edit mode, then bind the data source to the GridView. Your EditItemTemplate would contain a Cancel and a Save button. Cancel would re-bind the GridView to the underlying data source without the empty row and set EditItemIndex to -1, thereby removing the row from the GridView.
How to easily insert row in GridView with SqlDataSource
If you add a new row to the datasource, even if the row has empty values, and you databind the datasource to the Gridview, it should show up as an editable row just like any of the other rows.
I have a gridview full of telephone numbers. To populate the gridview I bind the gridview's datasource to a List<> of telephone numbers. I do this when the page is first loaded, but not on postbacks.
I want the user to be able to delete some of the telephone numbers, and then, if they want, click a Save button, and this will update the database, otherwise their changes will be ignored. So I have a button in the grid, and an event is fired, and I can call DeleteRow(row index) and remove the row from inside this event. For some reason this doesn't work.
All the gridview examples I find on the Internet execute the delete straight away by calling an sql function, and then bind again. And some examples bind the grid every time the page ios loaded, which seems inefficient.
My questions is:
The delete button causes a postback to the server. On postback the list of telephone numbers no longer exists. And the gridview's datasource is null. The grid is no longer bound. But there must be data somewhere, because the data in the grid is still visiable. Where is this data, and can I delete a row of it, so that a row in the gridview is deleted?
The viewstate saves the contents of the datagrid, so the answer is "The Viewstate"
Understanding the viewstate is essential to understanding how ASP.NET works, so rather than posting just enough info to answer your question, I'm going to recommend you read the entire article I linked to.
You can use jquery , you need to save the Datakey value of each deleted row in a hidden field
and hide the selected row , and when user clicks save , u can delete the rows based on hidden field values # code behind.
I have created a GridView whose columns are dynamically created based on my data source. I have implemented these columns by using the approach described here.Those columns display properly on the initial load. However, I need to implement commanding so that a user can edit / delete a row in the GridView.
At this point, I have implemented commanding as I would with a normal GridView. I have a TemplateField with an ItemTemplate that has LinkButton elements for edit and delete. The CommandName for each LinkButton is set to either Edit or Delete respectively.
Oddly, when a user clicks either the Edit or Delete link, the data in the GridView disappears. However, I have verified that I am in fact re-binding the data when one of these LinkButton elements is selected.
Can anyone provide some suggestions as to what the cause could be?
Thank you!
Here are good examples. You can figure out postback issue.
http://quickstarts.asp.net/QuickStartV20/aspnet/
I have a RadGrid bound to a LinqDataSource. The grid has auto generated Edit and Delete columns. It displays a simple table without any hierarchical organization.
I am taking the following steps.
Populate a RadGrid using a LinqDataSource
Click Edit on the last row of the grid
From another control on the page, update the linqdatasource and call rebind on the grid
The grid loses track of the current editing item, and opens a different item in edit mode
Please help.
If you rebind the datasource, everything will be reset. You will need to keep track of the current 'edit' item, and 're-activate' it after your rebound the datasource.
Make sure that:
All binding occcurs in the OnInit event (or after the button click is handled)
Viewstate is not disabled for the grid