Details View in Asp.net, Set it to NEW - asp.net

I have a grid view on my page, and a hidden details view.
When the user wants to add a new entry, they will click a button, and the gridview will become hidden and the details view will become visible. The only problem is I want my details view to automatically be set empty in the NEW mode, without them having to click the new in the details view form.

In the RowCommand event of the gridview:
myDetailsView.Visible = true;
myDetailsView.CurrentMode = DetailsViewMode.Insert;
myGridView.Visible = false;

On button click change the mode like:
DetailsView1.ChangeMode(DetailsViewMode.Insert)

Related

I have a table with records. No matter which View button I click, the bottom record is displayed

I have a table with a list of records. Each record has a View button. But no matter which View button I click, the bottom record (Acme6) gets opened?
enter image description here
It looks like you are sharing datasource for your list and details pages. If my assumption is correct, then you need to modify your view button event handler as follow:
// onClick event handler for View button
var rowItem = widget.datasource.item;
var listDatasource = widget.parent.parent.datasource;
listDatasource.selectKey(rowItem._key);
app.showPage(app.pages.DetailsPage);

Telerik RadGrid maintain scroll position after row selection

I have a RadGrid that has a WebUserControl for each row of the grid to allow the user to edit that row. When I click the edit button to expand the row (this opens up a .ascx control within the grid for that row), it always scrolls to the top of the page. The user then has to scroll down to find the row they selected with the row expanded to begin editing that row.
I found in another post that adding RadGrid1.ClientSettings.AllowKeyboardNavigation = true; prior to data binding the grid helps to maintain scroll position. This kind of works and you only have to scroll down one click of the mouse wheel to find the row to edit; not good enough.
I also have set MaintainScrollPositionOnPostback=“true" on the aspx page.
I also have set on the RadGrid itself under client settings SaveScrollPosition=“true".
What I'd like to see is the page not move at all when the user clicks on edit for the given row. I would like to maintain the scroll position on the page.
Can this be accomplished? If so, how?
I finally figured out why my grid always scrolled to the top. It was my fault. I wanted the user to see any message from the WebUserControl when control pass back to the parent page. The RadGrid1.ClientSettings.Scrolling.ScrollTop = 0; was the issue.
I had the following code listed:
private void DisplayMessage()
{
// Display any messages from RadGrid2 that occurred in WebUserControl
if (!string.IsNullOrEmpty(Convert.ToString(Session["LabelUpdated"])))
{
lblUpdated.Text = Convert.ToString(Session["LabelUpdated"]);
Session["LabelUpdated"] = null;
}
RadGrid1.ClientSettings.Scrolling.ScrollTop = "0";
lblUpdated.Focus();
}
I've since changed it to what is below:
private void DisplayMessage()
{
// Display any messages from RadGrid2 that occurren in WebUserControl
if (!string.IsNullOrEmpty(Convert.ToString(Session["LabelUpdated"])))
{
lblUpdated.Text = Convert.ToString(Session["LabelUpdated"]);
Session["LabelUpdated"] = null;
RadGrid1.ClientSettings.Scrolling.ScrollTop = "0";
lblUpdated.Focus();
}
}
After the change the grid will only scroll to the top when a message is present from the WebUserControl.

My button click is working only the first time

I have a classic ASP NET page on my SharePoint site with several buttons in it:
Button importZIPPOTBtn = new Button();
importZIPPOTBtn.Click += new EventHandler(importZIPPOTBtn_Click);
this.Controls.Add(new LiteralControl("<br/><br/>"));
this.Controls.Add(importZIPPOTBtn);
The first click on any button is perfectly firing the event, but any further click on any button doesn't fire, I can't understand why...
Consider aadding button to form1 or container element like panel inside page.
Button importZIPPOTBtn = new Button();
importZIPPOTBtn.Click += new EventHandler(importZIPPOTBtn_Click);
this.form1.Controls.Add(new LiteralControl("<br/><br/>"));
this.form1.Controls.Add(importZIPPOTBtn);
You can verfiy in html source, unless you add this way even literal control containing lines breaks will not be rendered.

Telerik RadComboBox AutomaticLoadOnDemand

I use Telerik RadComboBox in my project. I set EnableAutomaticLoadOnDemand="true" on RadComboBox. It works good but when I want to set selected item on load of page event, it doesn't show selected item
With load on demand mode, so combobox does not have any item. It just has item(s) when you action on it.
In my opinion, you should get the specific item and add it to combobox manually on page load event like this way (I'm not sure the structure, just an idea.)
if (!IsPostBack)
{
var itemSelected = service.GetById(Id); //item Id
this.combobox.Items.Add(new RadComboboxItem(itemSelected.Id, itemSelected.Name));
this.combobox.SeletedValue = Id.ToString();
}
RadCombo allows to set up SelectedValue and Text properties even through there are no items in it.

How do I programatically put telerik rad grid in "add new" mode on page load

Seems like this should be easy but I must just be missing something... I have a Telerik RadGrid on a page that allows inline editing. How do I programatically put the grid into edit mode to insert a new row into the grid. When the page loads I would like show the existing data and also display 1 empty row that a user can easily type into to add a new record to the table. (I don't want them to have to push the add new button)
Found the answer while back.... updating this in case others need it
RadGrid1.MasterTableView.IsItemInserted = true;
RadGrid1.Rebind();
Lifesaver!!
You can set
radGrid1.MasterTableView.IsItemInserted = false;
radGrid1.Rebind();
that will remove the inserted item (like pressing cancel).
If you need show inset form always you can use next:
protected void NeedDataSource(object sender, GridNeedDataSourceEventArgs e) {
parametersGrid.DataSource = data;
parametersGrid.MasterTableView.IsItemInserted = true;
}
You could try using jQuery to press your add button once the page is ready.
Something along the lines of -
$(document).ready(function() {
$("#addButton").click();
}
What I did when I wanted to do the same with the Telerik grid is to set the MasterTableView.IsItemInserted property of the control to true inside the OnNeedDataSource event handler. I suppose that it should work if you set the property inside the OnDataBound grid handler as well.
Dick
RefreshGrid(userName, "priority", true, false);
RadGrid radGrid = RadGrid1;
radGrid.MasterTableView.InsertItem();
radGrid.Rebind();

Resources