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
Related
How do i multiple details view controls based on number of records i retrieved from the query in same page with delete button?
My query may returns multiple records or one record. I could have bind the result in a grid view table but what i would like to do is iterate over the number of records and create details view in each tile dynamically. How do i dynamically created details view with delete button and bind the data?
How do i achieve this? I have never worked with asp.net web form.
You can use repeater and its ItemDataBound and ItemCommand.
ItemDataBound is an event that fires once on your server for every record bound to the control. It is fired everytime a new item is binded to your data control.
ItemCommand is the event that will fire if you click a command button that is associated with the record. It is fired when the command event for a Button or LinkButton or ImageButton inside the data control is used.
use grid views rowdatabound event for iteration its explained in detail in here with example
https://www.c-sharpcorner.com/UploadFile/1e050f/rowdatabound-event-in-gridview-in-Asp-Net/
as for html in grid refer to
I am trying to figure out what the correct event would be to populate a ComboBox in a Telerik RadGrid or any ASP.NET grid from the CodeBehind. When the user clicks Edit on a row the ComboBox should be populated with its items.
The only examples I have seen are using the DataSourceID property in the aspx page. I prefer doing all of my populating manually in the code behind:
ComboBox1.DataSource = colorList;
Combobox1.DataBind();
You can access child controls in a grid column in:
ItemDataBound - fired for each item (so you need to check for GridDataItem types or GridEditItem, depending on your goal)
ItemCreated - similar, but you don't have the data item object associated with each item
ItemCommand - when Edit is clicked an Edit command is invoked so you can access it.
I have an update panel that includes a dropdownlist control and a detailsview control. The dropdownlist is populated by a sqldatasource control which grabs the data from a table called Places (just a list of venues). The detailsview is insert mode only and inserts places into the database table that populates the dropdownlist. I am trying to allow someone to insert a new place inside the update panel and have the dropdownlist refreshed at the same time so the user will see all places in the dropdownlist, including the one they just added with the details view. Right now, the detailsview is adding the place to the database properly but not updating the dropdownlist. If I refresh the page after adding a new place, the droplist updates with the new place. Any suggestions?
Disclaimer: This answer was posted before any code was posted in the question.
This also assumes both controls are inside the update panel.
In the event handler for Updating or Inserting for your DetailsView control, you need to add the following code:
MyDropDownList.DataBind()
And, worst case scenario, you can do this if the update panel is causing you problems. It's not the greatest performance-wise though.
Response.Redirect(Request.RawURL)
I am trying to update controls in the of a ListView control after handling the ItemCommand event.
My ListView displays line items of a purchase order in the as html table rows along with a TextBox to enter a new quantity and a Button to update the quantity. My ListView then displays sub-totals, discounts, and a grand total of the line items above in the as html table rows as well. On initial load, I set the values of the controls in the ListView's in the LayoutCreated event handler.
When a new quantity is entered and the button to update is clicked, I handled the event in the ItemCommand event handler. I update the quantity of the specific line item. I then re-bind my ListView to the underlying collection and call DataBind(). The problem is, LayoutCreated is not fired this time around, only on initial load.
My work around is to just pull those controls out of the and address them as static controls, but I like having them inside because my table markup can be fully contained in the and my can show cleanly without having to juggle the static controls' display properties.
Is what I am asking possible? Thank you for any help you can provide.
I'd reccomend handling the DataBound event of the ListView (instead of the LayoutCreated event), and setting the values there. That will get called everytime you re-bind the ListView, as well as when it loads for the first time, which (from your description) is what you want to do.
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.