error when canel row in gridview - asp.net

this error apear when I try to cancel row in grid view
The GridView 'GridView1' fired event RowCancelingEdit which wasn't handled

In the mark up, add row cancelling edit event for the gridview
RowCancelingEdit="GridView1_RowCancelingEdit"
In the code behind add,
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//switch back to default mode
GridView1.EditIndex = -1;
//Bind the grid
Gridview1.Datasource=yourDatasource;
GridView1.DataBind();
}

If this is ASP.NET then you may have specified the name of the handler in the ASP.Net page and not implmented it in the Code Behind page.
Can you post the code where it is defined?
You will have
<asp:GridView ID="GridView1" runat="server" RowCancelingEdit="MyFunction">
Just remove the RowCancelingEdit section

Try checkng the value of "EditItemIndex" in page prerender, see if it get chaged after the first postback.
With Gridview after setting the EditItemIndex, you have to do a rebind usually by just calling your GridView1.DataBind()

Related

How can I get selected item in DropDownList ASP control in Page_Load method?

I have DropDownList inside my ASP page.
When selection changed postback accured and the Page_Load method fired.
I need to get selected item(selectedValue and selectedIndex) in Page_Load method.
I know that I can use selectedIndexChanged event handler, but in my case it is not
suitable solution because of incorrect architecture.
Any idea how to get selected item in DropDownList control in Page_Load method.
With incorrect architecture is it useful to write
var selectedValue = Request.Params[drpDownList.UniqueID];
You should be OK as long as you check for postback -
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
var index = ddlDropDown.SelectedIndex;
// do stuff
}
}
I'm assuming that the control isn't dynamically created.

Missing selected value from RadioButtonList after PostBack

First the page loads and shows an empty textbox and a button "GO"
Upon clicking the button "GO" a radioButtonList already in the page is loaded from a table based on the text in the textbox.
The radioButtonList is shown with new button "Made my choice".
The user chooses a button and clicks "Made my choice".
Upon checking for selected value or index the radiobuttonList is not checked at all...
That is it
TVM
Ricardo Conte
If you are not using Page.IspostBack property into your Page_Load then Try to use it
if(!Page.IsPostBack)
{
// Your Code..
}
into your Page_Load.Check MSDN
Hope it works for you.
protected void Page_Load(object sender, EventArgs e)
{
// Your code execute always
if(!Page.IsPostBack)
{
// Code which is execute without postback
}
}

Hide databound RadGrid rows

I have a telerik radgrid in my .aspx page name rgLowRise, and I have an ObjectDataSource as the DataSource set like rgLowRise.DataSourceID = odsLowRise. This works fine, but I want it not to show any records at first load, how can I do that? And I have to use DataSourceID and not DataSource due to some reasons.
Thanks
You can remove the DataSourceID from the markup or your code behind (Page_Load) and set at a later stage, e.g. Button_Click or some other event
protected void Button_Click(object sender, EventArgs e)
{
rgLowRise.DataSourceID = odsLowRise; //until you click this button, the grid would display nothing
}

ASP.net Gridview Paging doesin't work inside UpdatePanel

Although, questions somehow similar to this have been asked for a number of times, but the question is still unsolved. Here is the question:
I have a GridView which is contained in a tab container AJAX control which itself is inside an UpdatePanel. Gridview works excellent and its corresponding methods are fired accurately, but when I enable paging(e.g.) after I click on page 2, the GridView hides itself. here is my PageIndexChanging() method:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
UpdatePanel2.Update();
}
Why paging causes GridView to stop working correctly? What can I do?
The solution is that you should refill the dataset which is used to populate the gridview, each time your page index is changed. By this way, you could ensure that in each seperate postback which has been triggered by the gridview page number, results will be populated.
I just tried that above code. I had same issue and now it is working just fine.
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
// UpdatePanel2.Update(); <-- Remove this line from your code.
}
I have GridView inside update panel. Did you write your event PageIndexChanging in your .aspx file also?
Hope this helps.
Further research:
http://msdn.microsoft.com/en-us/library/cc295545.aspx
Controls that are not compatible with UpdatePanel controls
The following ASP.NET controls are not compatible with partial-page updates, and are therefore not designed to work inside an UpdatePanel control:
GridView and DetailsView controls when their EnableSortingAndPagingCallbacks property is set to true. The default is false.
I had the same issue , changing the updatepanel property UpdateMode="Conditional" to UpdateMode="Always" and setting the property ChildrenAsTriggers="true" solved the problem for me.
To do it, you have to re set the datasource in the page index change event. The performance will be lower but that's the way you can make it works.
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.DataSource = ;//Set again the datasource
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
UpdatePanel2.Update();
}

Can't see next page in gridview

when I use " AllowPaging="True" " property in gridview and upload my webSite ,when I click next page , I can't see that and I see same record that I see already . point : I bind a dataBase on gridview,and I see that in gridview.above problem when I uplaod my website,happen . what is problem that I can't see next page of gridview ?
I am having a bit of trouble completing understanding your question. I think your are basically trying to get paging to work on a gridview.
In addition to setting "AllowPaging=True", you will need to hook into your paging event like so:
void GridView_PageIndexChanging(Object sender, GridViewPageEventArgs e)
{
e.NewPageIndex = e.NewPageIndex + 1;
DataBind();
}
Check it out on MSDN
you need to set the current page index property in Page index chaged event. then call the bind method in next line. then only you able to see the next page and it will work.
example
protected void SearchGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//set the current page index for grid
searchResultsGrid.PageIndex = e.NewPageIndex;
//Bind the result sets
BindSearchResults();
}
Custom control would help to avoid writing on page level event handlers

Resources