Forms Data Controls :: Sort Even Does Not Get Fired In Gridview?
Mar 24, 2011
I am using gridview created by visual components. I have registered gridview_onsortclick event during the page initialisation, but when i try to click on the header of any column, this event does not get fired at that time. This event gets fired only after all the controls, sorting query is generated, filling the current dataset is done. But the same event is getting fired before query is generated and dataset is filled,for the other page. And one more thing to add with it, I want the sort function to be done on the whole dataset regardless of current page. Why is there such a difference in both the pages?
If the grid column is clicked to sort i dont want to retireve data agian, i can get it from viewstate, but i dont know if that triggered the post back or if the ImageButton on the page triggered it
I have a page displays CRM data (with CrmService) in GridView. Everything run ok until I tried to sort out one field by default and I received the following exception: The GridView 'GridView1' fired event Sorting which wasn't handled. The reason I am using GridView to do the sorting because:
1) Cannot do it with SQL "ORDER BY" since date retrieval from CRM Web Service
2) Cannot use OrderExpression for QueryExpression from CRM because the column I want to sort is generated by my algorithm
GridView1.Sort("ColumnName" SortDirection.Descending); in Page_Load, or Button1_Sort(object sender, GridViewSortEventArgs e), they all trigger the above execption!
I also added the method to the following method to handle exception, but didn't work:
Just spent about 8 hours googling and looking through this forum for a solution on how to make sure that I can dynamically sort. Here is the situation.
I have 1 Gridview that displays 10 different scenarios based on what button is clicked.
I am also returning only top 10 records. I am doing all of the data binding pragmatically. So I have BoundFields, HyperLinkFields etc.
I also want to sort some records. When I change DataSource SQL statement the gridview somehow remembers what the last sort value was and it errors out saying that value "x" cannot be sorted because it does not exists.
Here I get an error that says that the data source does not support sorting? Doesnt it say gridview1.allowsorting = false;
I also tried gridview1.sort("", SortDirection.Ascending); This does nothin... except query my database one more time because i have a onSorting event that looks like this:
[Code]....
Here is an example of just one of those SLQ statements inside GetSQLQuery:
I have a gridview with data. I want a button which is not part of the gridview. Then if I press a button the gridview is sorted by two colums. i.e column1 ascending column2 descending.
I am not looking to work with a Sqldatasource as I use a data access layer. So the sort would have to be from a datatable and databind or directly with the gridview.
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 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?
I have a gridview with a button. When the button is clicked another gridview should show up showing some details of the clicked row.The strange thing is: when the button is clicked, the rowcommand method is NOT fired! When I place the code on a separate page the event is fired, but when placed inside the tabcontainer for some reason it isnt...
I want to create simple rating page where player's place,name and rating is displayed. I've created database with ID,Name and Rating Columns, binded Gridview to this database and created TemplateField "Place". With following code I've created numbered list for Place:
protected void Page_Load(object sender, EventArgs e){ for (int i = 0; i < GridView1.Rows.Count; i++)
I'm a newbie to .NET, so the solution might be really trivial. I have a database, I have an Entity Data Model, I add in my Index.aspx page an EntitryDataSource and a GridView. I connect them and everything works fine (the data is displayed as expected). The problem is that clicking on the coulmn name or on the pagination lists doesnt do a thing... Although I did set the properties AllowSorting="True" and AllowPaging="True". I also tried with another datasource type (SqlDataSource) and the same problem.
i am having a gridview in which all columns get dynamically added, i applied sorting in it, all column added as boundcolumn get sort properly but two column which are added as templated column do'nt get sort. Though my dataview have these column as it is.
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:
Is there a way to Sort a Gridview by a Calculated Column? I have a gridview with template fields using lablels and a linq datasource. Those columns sort just fine. I can not get the Calculated column to sort, because there is no sort expression to use...