Retrieving Gridview's Sort Expression And Direction Via Javascript?

Aug 16, 2010

I was given help in a previous topic located here: Accessing Gridview In Another Form In this topic I had gridview rows that are selectable and a search window that returned search results. We found a way for me to select a row in the parent window of the search one. My issue now is that when the parent windows gridview is sorted, the function no longer selects the correct row. I was wondering if there was any way to access the gridviews sort expression and direction, or some other way I can do this so it accounts for sorting. Relavent code is as follow: This is in my parent window

<script type = "text/javascript">
function selectRow(index)
{
//Retrieve a reference to the table that represents the GridView
var gridView = document.getElementById('<%=gvSideList.ClientID%>');
if(gridView)
{
//If able to get a reference to the table representing the GridView...
var doPostbackArgument='Select$'+index;
__doPostBack('<%=gvSideList.ClientID%>',doPostbackArgument);
}
}

This is in the child window

<script type = "text/javascript" >
function selecttherow(index)
{
window.opener.selectRow(index);
}
</script>
protected void gvresults_SelectedIndexChanged(object sender, EventArgs e)
{
//declare variables
GridViewRow row;
int index;
int id;
//retrieve index, row, and id from gvresults
index = gvresults.SelectedIndex;
row = gvresults.Rows[index];
id = Convert.ToInt32(row.Cells[5].Text);
//fill a datatable from general with id's for selection
SqlCommand cmd = new SqlCommand("SELECT ID FROM General", csbg);
cmd.Parameters.AddWithValue("@id", id);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
//loop through the dt and find the index of the matching id from the search window
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i]["ID"].Equals(id))
{
//execute script to select the matching row in the dataentry page
string script = "";
script += "selecttherow(";
script += i;
script += ");";
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "selecting", script, true);
break;
}
}
}

Let me know if you need me to further clarify anything.

View 7 Replies


Similar Messages:

Gridview - Capturing Sort Direction

Feb 2, 2011

I have a gridview in an updatepanel with sorting enabled and an event handler as follows:

protected void MyGridSort(object sender, GridViewSortEventArgs e)
{
var TheDirection = (e.SortDirection).ToString();
var TheColumn = (e.SortExpression).ToString();

I put a breakpoint just after these lines. Every time I press the column header, my variable TheDirection is always showing Ascending. Why is it not toggling from ascending to descending and back?

View 1 Replies

Forms Data Controls :: Gridview Sort Expression - How To Reset A Gridview Or Prevent It From Doing A Sort

Sep 23, 2010

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.

I tried this:

Tried setting gridview1.sqldatasourceid = null; gridview1.allowsorting = false; gridview1.databind();

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:

[Code]....

View 1 Replies

C# - GridView Sort Expression Must Return Not Empty Data

Mar 1, 2010

My program running good. But i try to add up-down icon on my gridView header. but if i make it, My break point should drop below "if comparison" For example; field.SortExpression=Category but every time CustomersGridView.SortExpression is empty when gridview.SortExp is not empty.

foreach (DataControlField field in CustomersGridView.Columns)
{
if (field.SortExpression == CustomersGridView.SortExpression)
{
return CustomersGridView.Columns.IndexOf(field);
}
}
i need :
foreach (DataControlField field in CustomersGridView.Columns)
{
if (field.SortExpression == "Category")
{
return 2;
}
}
CustomersGridView.SortExpression must not be empty!!!!!
MY source:
<head runat="server">
<title></title>
<link type="text/css" href="StyleSheet.css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView
ID="gvCustomers" runat="server" CssClass="tablestyle"
AllowSorting="true"
OnRowDataBound="GvCustomers_RowDataBound" AutoGenerateColumns="false">
<AlternatingRowStyle CssClass="altrowstyle" />
<HeaderStyle CssClass="headerstyle" />
<RowStyle CssClass="rowstyle" />
<Columns>
<asp:BoundField HeaderText="Kategori" DataField="Category" SortExpression="Category" />
<asp:BoundField HeaderText="Tarih" DataField="Date" SortExpression="Date" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
protected void GvCustomers_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridView gridView = (GridView)sender;
if (gridView.SortExpression.Length > 0)
{
int cellIndex = -1;
foreach (DataControlField field in gridView.Columns)
{
if (field.SortExpression == gvCustomers.SortExpression)
{
cellIndex = gridView.Columns.IndexOf(field);
break;
}
}
if (cellIndex > -1)
{
if (e.Row.RowType == DataControlRowType.Header)
{
// this is a header row,
// set the sort style
e.Row.Cells[cellIndex].CssClass +=
(gridView.SortDirection == SortDirection.Ascending
? " sortascheader" : " sortdescheader");
}
else if (e.Row.RowType == DataControlRowType.DataRow)
{
// this is an alternating row
e.Row.Cells[cellIndex].CssClass +=
(e.Row.RowIndex % 2 == 0
? " sortaltrow" : " sortrow");
}
}
}
}

View 1 Replies

Web Forms :: The Control Doesn't Remember The Last Sort Direction?

Mar 2, 2011

Asp.net.3.5 gridview on sorting problem The control not remember the last sort direction on the source side

AllowSorting="True"

EnableViewState="true"

on the server event

[Code]....

View 2 Replies

Forms Data Controls :: Modifying A Gridview Sort Expression?

Jan 31, 2011

I have a gridview of the following form below

ID Expirydate
A 1/02/2011
B 2/02/2009
C 3/01/2009

and I would like to modify my sort expression so that when the expirydate header is clicked on, it will make all those id that has expired pop to the top . In this case, we will have the following as the results

ID Expirydate
B 2/02/2009
C 3/01/2009
A 1/02/2011

View 6 Replies

Web Forms :: GridView Sorting Only Works In One Direction?

Apr 12, 2012

My Gridview sorting only works only one way means it works only desc order not by asc order.  

below is my code:

Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
         If Not Page.IsPostBack Then
           Gridview1.Visible = False
        End If
    End Sub
Protected Sub Submit_Click(sender As Object, e As System.EventArgs) Handles Submit.Click
              Gridview1.DataSourceID = Nothing

[code]....

View 1 Replies

C# - Retrieving The Alt Text For A Control In The Javascript?

Jan 31, 2010

i have a image button placed for each row of a datagrid? using item template

i am just adding the alt text for each image at the datarowbound event?

the problem is it possible to retreive the alt text for theimages at the mouse over so that i could just display the alt text in the message box

View 1 Replies

Retrieving JavaScript Data From A Post?

Oct 19, 2010

I'm using the WYSIWYG editor TinyEditor (http://www.leigeber.com/2010/02/javascript-wysiwyg-editor/), and I'm having an issue recalling the updated data. I searched the forum and found someone else had the same issue:

http://forums.asp.net/p/1526709/3684896.aspx#3684896?Accessing+textarea+value+in+code+behind

Thing is, I think I've done everything in the post, but my code is just not working. When I click submit, the variable in the code behind (val) isn't capturing any data
- Object reference not set to an instance of an object.

Here's my code:

[Code]....

And the code behind:

[Code]....

View 5 Replies

VS 2008 - Retrieving Mail Attachment In JavaScript

Jun 29, 2011

My ex colleague created a few pages using server side javascript. What we are doing is connecting to a pop3 account and retrieving emails. We use a free component called OSPOP3. It works well but I'm having trouble getting the attachments of each email object. This is my asp code:

Code:
Set Session("oSession") = Server.CreateObject("OSPOP3_Plus.Session")

that's creating the object.

this is the server side js:

Code:

everything works fine ablove except the line i highlighted in red. I don't know why I cant get the attachment name or any of its properties. The attachment count is 1 which is correct.

I get this error:

Code:
Microsoft JScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment

In classic asp or asp.net I can do this and everything works:

Code:
For Each a As Attachment In msg.Attachments
Dim a_Name As String = a.AttachmentName
Next

I can't even console.log the object because it is server side javascript. I have to try to fix it in the ssjs because his code is doing quite alot of stuff and I don't have time to rewrite everything ....

View 16 Replies

Forms Data Controls :: Getting The Custom Sorting And Paging With Images To Indicate The Sorting Direction In Gridview

Jul 18, 2010

Moderators Note: THIS ISSUE IS BIG FOR ME AND EVEN IF POSSIBLE, GET THE REPLY FROM THE DESIGNER OF GRIDVIEW. I have been looking for him for long. I am really fed up with reviewing a good lot of web pages on how we can possibly customize the gridview to enable sorting and paging. So many sites have listed out a lot of information and so many guidances. But the problem is that one works out fine and the other is a burden. I really feel bad about being given the job of customizing this kind of a gridview which has no user friendly approach to it. Also, this control is rendered without the pager links inside the <tfoot> tag. I have tried the Pear Pager in php. It is that good and easy to use and compared to that, the gridview in asp.net is the worst ever control i have ever tried so far.

1. i can use the images to indicate the sorting direction
2. I can have the custom pager like

[code]

<<Previous 1 2 3 .. 7 Next >>.

[/code]

When i click the next when i am viewing the page at 3 , the pager links should change as

[code]

<<Previous 2 3 4 .. 7 Next >>

[/code]

Kindly look into this type of requirement and firstly tell me whether this is possible with the gridview control. I would like this request even to be escalated to the designers of the gridview control also, so that Microsoft comes out with a reply THAT WORKS and not the kind of stuff like surfing through a lot of links and pages and finally wasting a lot of days precious time and still breaking the head with this useless control. I have spent a lot of time in searching for a perfect way. Not writing a code that is non-standard. I am really serious b'cos I have spent weeks in customizing this control. If I dont get a solid reply atleast now, I am going to generate all the output by HTML content by custom coding.

View 7 Replies

Forms Data Controls :: How To Change Sort Column Header Text And Retain The Sort Link

Jun 3, 2010

I have a simple dynamic gridview with following code -

GV = new GridView();

View 3 Replies

AJAX :: Retrieving The Content Of The HTMLEditor On The Client Side In JavaScript

Oct 12, 2010

retrieving the content of the HTMLEditor on the client side in Javascript

I have tried:

$get(context._ReviewTxtID).getContent()
$get(context._ReviewTxtID).Content
$get(context._ReviewTxtID).value

nothing seems to work

View 1 Replies

Forms Data Controls :: Gridview Sort Manually With Button Outside Of Gridview?

Jan 18, 2011

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.

View 3 Replies

Javascript - How To Create A Regular Expression For Cricket Overs

Jan 25, 2011

what regular expression should i use to validate cricket overs in textbox. like it can be 5.1, 5.2,5.3,5.4,5.5 but it should not contain fraction value greater than .5 ,also the values should be numeric only (float and int)

View 3 Replies

Web Forms :: DataView.Sort Vs List.sort?

Mar 7, 2010

Actually i want to ask which is the best for sorting in Asp.Net is it DataView.Sort Method or List<Object>.Sort() method.

View 1 Replies

Web Forms :: Sort Datatable Without DefaultView.Sort?

Apr 20, 2010

I'm looking for a way to sort the rows of a datatable without setting the DefaultView.Sort to a specific column. I have a datatable in session that users can add records to. I want them to be able to sort the data by clicking on a button. But new records added after that need to show up at the bottom of the list until the sort button is clicked again.

View 2 Replies

VS 2008 What's The Most Efficient Way To Sort A Gridview(vb.net)

Oct 28, 2010

What's the best way to do this? I have seen quite a few examples that use a Dataview etc. what is the best method. I'm thinking about speed issues when a grid has a few thousand records etc.

this is how I populate the gridview:

Code:

[code]....

View 5 Replies

C# - Way To Sort GridView Bound To DataTable

Jul 13, 2010

I have a repository that contains all of my LINQ queries for this project that I am working on. I am able to get the LINQ results to a DataTable and bind that to a gridview for displaying the data. Now I need to make the gridview sortable. I have set AllowSorting="true" and I have the OnSort event handled in a routine in the codebehind.

View 2 Replies

C# - Sort Gridview Using Dropdown List

Mar 8, 2011

the specific example i am referring to is this site [URL] notice the sort by drop down list. basically i want to sort products according to price,name,popularity? do i have to requery the database and retreive the sorted data in gridview again, or should i already sort the items in the gridview that are already there? I tried to this but its the wrong approach, basically i was trying to repopulate data in the page load event, which was giving error.

View 2 Replies

C# - How To Sort A GridView By Clicking On The Header

Feb 4, 2011

I want to sort a GridView by clicking on the header. I guess all i need is the header name and then pass it into sql to get the data back sorted. How is it possible to get the header name?

View 3 Replies

ADO.NET :: Gridview Dynamic Sort Using Linq?

Mar 21, 2011

Loading data into gridview, retieving data using linq,I have a method that accepts two paramters that would sort specific field and return the object to the gridviewi.e.

passing into the method GenerateData(string sortExp, string sortDir)
sortExp = "Name", sortDir = "descending"
linq query://works

[code]...

View 2 Replies

C# - Sort Gridview With Dynamic Linq?

Feb 2, 2011

I have a gridview with several columns, 3 of which I'd like to sort. The source for the data is held in the session.

protected void MyGridHistorySort(object sender, GridViewSortEventArgs e)
{
var TheColumn = (e.SortExpression).ToString();
TheDataHistory = (List<ViewDataHistoryModel>)Session["SessionDataHistory"];
var test = "data.DataDate";
var NewDataSource = from data in TheDataHistory
orderby test
select data;
MyGridHistory.DataSource = NewDataSource;
MyGridHistory.DataBind();

DataDate is a valid column in the list but the orderby statement doesn't work. Ideally, I'd like it to sort with the variable TheColumn by writing something like test = "data."+TheColum; and then add a sort direction based on a boolean. I looked at the OrderBy extension method NewDataSource.OrderBy(test); but that doesn't work either.

View 3 Replies

C# - Sort Only Displayed Rows In Gridview?

Mar 9, 2010

I have a gridview with paging, which displays 5 records in each page.

How can I sort the elements of the current page only?

And other pages should not be sort?

I am using ASP.NET and C#.NET.

Is there any way to do this in LINQ?

View 1 Replies

Web Forms :: How To Reset Gridview Sort

Feb 25, 2012

<asp:GridViewid="gridview"
runat="server" DataSourceID = "SqlDataSource1"
       PageSize="30"  EmptyDataText = "No Records Found" EmptyDataRowStyle-HorizontalAlign ="Center"
               AllowPaging="true"    
    HorizontalAlign="Center" BorderColor ="Black"   Width = "762" Font-Names="Calibri"

[Code] ....

First time on page load 

Sorting works fine 

But if I done sorting on gridview column then its always the same , How to assign result of SQL query to my result 

so that my sort will show result from sql query order  not the order of grisview sort ...

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved