Forms Data Controls :: ListView Ajax - Use A LinkButton Then The Page_Load Event Is Fired?
Feb 3, 2011
I have discovered something strange when using a ListView. I have a listview contained inside an uodate panel and everything works OK until I edit the editItemTemplate to use a LinkButton instead of a Button.When i use a LinkButton then the Page_Load event is fired.
So I have a GridView control with autogenerated column set to true, it also has autogenerated Edit and Delete buttons, sorting and paging, and also I am binding this same gridview to multiple data sources at runtime. All is working well.
Now I am adding a dynamically generated footer row at runtime. This footer row will allow users to add new record regardless which data source it binds to. So it is working as well except there's a small bug I couldn't figure out why. It's when I navigate to the last page of the gridview, if the rows on the last page is less than the page size, for example, I have page size 10 and the rows in last page is 9, then when I click the 'Add' linkbutton, the Add event does not fire, instead, it fill the last page with additional blank rows, that means if the last page has 5 rows, it will fill 5 blank rows below, if it has 9 rows, it will fill 1 blank row below. Then if you click the add again, it will work. If the last page already has 10 rows then, it works just fine.
Below is the code I used to dynamically add footer row:
A breakpoint is set on FillForm() and this method is called two times but I can't explain myself why this happens. I have client side javascript code, when the form is being send, the onsubmit method is also called twice... Where do I have to search?! Is it a (known) bug? Think I could get it to work with this Thread: [URL] But why is the event fired within the onblur-event when it's fired anyway??
I'm trying to do a relatively simple thing, but just cannot get it to work. I'm trying to find a dropdownlist within a ListView ItemTemplate within Page_Load.
I have AjaxCOntrol tool kit Tab control on the page.When I set the ActiveTabIndex proferty programatically in button click event ..like
tabContainer1.ActiveTabIndex = 1;
Then the serverside event 'onactivetabchanged' is not fired.I set the 'AutoPostBack' property to True.When I click on the tab, then it will fire the 'onactivetabchanged' event properly, But when set programatically it woun't fire.
I have a rowDeleting even on my gridView. When I click Delete link, the Rowdeleting is not fired. I checked my aspx...and I have it there...I dont see any problems there..bu still when I click delete, my page is refreshed without calling RowDeleing event.
I have a very simple asp.net page, just some buttons and one GridView on it. The logic is a user click the QUery button,then the button click event was trigured to populate the gridview with data queried from database via LINQ. for a user friendly interface, in RowDataBound event, I visit every row, change a boolean value into checkbox represention. But it seem that the RowDataBound run twice, because the checkboxs were inserted twice for every row in one cell. so why? the source code snippet as follow:
Why wasn't my GridView's RowDataBound event fired? I have a masterpage on whick i have a query button, and I have a content page on which i have a customized GridView(named cgvEmployees,derived from GridView). The logic is when user click the button, the button click event triggered that search the underlying database and populate the GridView.
Everything runs great except that RowDataBound event isn't triggered. Because I have to change some cells' representations in RowDataBound event handler. I have surfed so much pages to find the answer but failed. Below is what i have already done:
1. set the autoeventwireup to true; 2. i have a cgvEmployees.bind() sentence in the button click event handler; 3. i have OnRowDataBound="cgvEmployees_OnRowDataBound" in the content page GridView tag attribute
by the way, the database query is coded by Linq Dynamic Query (please google 'dynamic Linq').
void Master_QueryButton_Click(object sender, EventArgs e) { RetiredEmployeeDataContext db = new RetiredEmployeeDataContext(); NameValueCollection nvcQueryKeyValue = getNVCQueryKeyValue(); Expression<Func<RetiredEmployee, bool>> searchPredicate = getLambdaExpr(nvcQueryKeyValue); IQueryable<RetiredEmployee> retireds = db.RetiredEmployees; Expression expr = Expression.Call(typeof(Queryable), "Where", new Type[] { typeof(RetiredEmployee) }, Expression.Constant(retireds), searchPredicate); IQueryable<RetiredEmployee> query = db.RetiredEmployees.AsQueryable().Provider.CreateQuery<RetiredEmployee>(expr); List<RetiredEmployee> employeeList = new List<RetiredEmployee>(query); List<RetiredEmployeeEO> employees = new List<RetiredEmployeeEO>(); foreach (RetiredEmployee employee in employeeList) { RetiredEmployeeEO employeeEO = new RetiredEmployeeEO(); employeeEO.MapEntityToProperties(employee); employees.Add(employeeEO); } cgvEmployees1.ListClassName = typeof(RetiredEmployeeEOList).AssemblyQualifiedName; cgvEmployees1.LoadMethodName = "LoadFromQuery"; cgvEmployees1.LoadMethodParameters.Clear(); cgvEmployees1.LoadMethodParameters.Add(employees); cgvEmployees1.DataBind(); } protected void cgvEmployees1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //Add the edit link to the action column. HyperLink editLink = new HyperLink(); if (((BasePage)this.Page).ReadOnly) { editLink.Text = "View"; } else { editLink.Text = "Edit"; } editLink.NavigateUrl = "employee.aspx" + EncryptQueryString("id=" + ((RetiredEmployeeEO)e.Row.DataItem).ID.ToString()); if(e.Row.Cells[0].Controls.Count==0) e.Row.Cells[0].Controls.Add(editLink); //Add checkbox to display the isactive field. CheckBox chkActive = new CheckBox(); chkActive.Checked = ((RetiredEmployeeEO)e.Row.DataItem).liveOrDead; chkActive.Enabled = false; if(e.Row.Cells[24].Controls.Count==0) e.Row.Cells[24].Controls.Add(chkActive); if (((RetiredEmployeeEO)e.Row.DataItem).gender.Equals((byte)1)) e.Row.Cells[2].Text = "Male"; else e.Row.Cells[2].Text = "Female"; if (((RetiredEmployeeEO)e.Row.DataItem).retiredOr.Equals((byte)1)) e.Row.Cells[14].Text = "Retired1"; else e.Row.Cells[14].Text = "Retired2"; if (((RetiredEmployeeEO)e.Row.DataItem).birthday.Equals("1753-01-01")) e.Row.Cells[3].Text = ""; if (((RetiredEmployeeEO)e.Row.DataItem).dayToEmployed.Equals("1753-01-01")) e.Row.Cells[6].Text = ""; if (((RetiredEmployeeEO)e.Row.DataItem).dayRetired.Equals("1753-01-01")) e.Row.Cells[7].Text = ""; if (((RetiredEmployeeEO)e.Row.DataItem).dayParty.Equals("1753-01-01")) e.Row.Cells[13].Text = ""; if (((RetiredEmployeeEO)e.Row.DataItem).daytoassign.Equals("1753-01-01")) e.Row.Cells[17].Text = ""; } }
I am creating a user control to serve as a multi select, multi column drop down. i.e more than one items can be selected. To achieve this, I used GridView control to dispay multiple columns when user clilck on image of drop down, first column containing CheckBox to select multiple rows. I have registered mouseout event handler for GridView control, to hide GridView when mouse leaves GridView area.
But mouseout event is going to be fired even mouse pointer moves from one row to another row. I have seen HTML in browser, mouseout is registerd in table rather than each row.
I have a Gridview which contains templated column that has 5 checkboxes in it. When you click on one checkbox, I want to uncheck the other 4.
I am using the Item Template for this. I don't want the user to have to Select a row, before clicking on the checkboxes. Here is my non-working code to uncheck the other checkboxes. I realize it's not "SelectedRow" that I want since there's no selected row, so how do I find the row containing the checkbox that fired off CheckChanged?
This is a weird issue. I have a List view with 2 Link buttons. "Edit" and "Delete" Iam able to attach an event handler for the first linkbutton(Update). Code in the event handler executed fine. But If I try to attach a event handler for the second link button(Delete) , I get an error.
My Item Template Looks like this.
[Code]....
First Item works absolutely fine. But If I attach the second handler, I get the following error
Am I missing some thing ? Note - There is no error if I try to attach the 1st event handler to the second link button.[ie EditLinkButtonClicked to DeleteLinkButtonClicked ] Issue occurs only when I try to attach DeleteLinkButtonClicked to DeleteLinkButton
I've got a gridview that returns student order history which works just fine. It pulls the StudentId from a hidden field on page load. I have a link button that ADDS AN ORDER when clicked. It calls a stored procedure, inserts the record, then rebinds the gridview and displays the new record at the top of the list.
Problem is when I go to EDIT it, i get this error... "The GridView 'GridViewOrderHistory' fired event RowEditing which wasn't handled." But the interesting thing is the error doesn't occur if I close the browser and reload the page and then click on that new record that was created. Obviously I'm missing something in my code when the new order is created. Here are the 2 subs involved in the process.
since APS.Net 4.0 I have a curious problem with an event.
There is a FormView and inside of the EditItem there is a GridView. In the Footer of the GridView I put Controls for inserting records.
But when I fire a markup defined RowCommand of that GridView then the same event is getting fired for the Parent FormView. First I had 'Insert' as the CommandName and so I was getting the Error that my FormView had to be in insert mode to insert a record. Then I changed the RowCommand of the GridView to 'xxx' and I got also the RowCommand 'xxx' at the RowCommand eventhandler of the Parent FormView.
The project was migrated from .Net 3.5 a few days ago, but nothing was manually changed in the code/markup. And the problem was not there with the "old" framework.
[Code]....
Of course, I could simply change the CommanName of the LinkButton e.g. to 'InsertChild' but I would like to know:
have extended a gridview to have all basic common functionalities like export to excel.So an image button will automatically rendered for exporting the gridview. I have added the link button in my extended gridview.when i click the button it gets postback. but the event does not get fired. I created the link button during overrided grid init method.and rendered during overided render method.I got stuck in this for a whole day..
On Button click(postback), my dropdownlist of gridview is getting blank, so i m getting error of "Object Reference...." on the line "ddl.selecteditem.value"Also, dropdownlist's selectedindexchanged event is fired on Button Click(Page Postback), which is making the dropdownlist to go blank. AutoPostBack of dropdownlist is set as False,
I am populating the gridview on the basis of listbox selection . However, I am setting the datasource in the click event after listbox entry. When i am trying to update any record in the gridview this error gets thrown because the datasourceid from the aspx page has been removed. Code for reference -
protected void btn_save_Click(object sender, EventArgs e) { ArrayList list = new ArrayList(); foreach (object o in ListBox2.Items) { list.Add(o); } string str2 = null, str, host; string str1 = "SELECT SYSTEMNAME, DATETIME, PDOWNTIME, UDOWNTIME, SYSDOWNMINS, REASON FROM PLANNED_DOWNTIME where "; host = Convert.ToString(list[0]); str2 = " ( SYSTEMNAME like '" + host + "'"; for (int i = 1; i < list.Count; i++) { host = Convert.ToString(list[i]); str2 = str2 + " or SYSTEMNAME LIKE'" + host + "'"; } str = str1 + str2 + " )"; string connectstring = "Data Source=SRCPA035\ovops;Initial Catalog=reporter;Persist Security Info=True;User ID=sa;Password=ril123"; DataTable dt = new DataTable(); SqlConnection connection = new SqlConnection(connectstring); try { connection.Open(); SqlCommand sqlCmd = new SqlCommand(str, connection); SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd); sqlDa.Fill(dt); if (dt.Rows.Count > 0) { GridView1.DataSource = dt; GridView1.DataBind(); } GridView1.DataSource = SqlDataSource1; } catch (System.Data.SqlClient.SqlException ex) { string msg = "Fetch Error:"; msg += ex.Message; throw new Exception(msg); } finally { connection.Close(); } }