How to sort data into GridViewhttp://forums.asp.net/t/1206311.aspx/1?How+to+sort+data+into+GridViewMon, 02 Mar 2009 08:18:43 -050012063112112671http://forums.asp.net/p/1206311/2112671.aspx/1?How+to+sort+data+into+GridViewHow to sort data into GridView <font color="#2b91af" size="2"> <p>&nbsp;</p> DataView</font><font size="2"> DV = DT.DefaultView;</font><font size="2"> <p>DV.Sort = </font><font color="#a31515" size="2">&quot;FullName&quot;</font><font size="2">;</font></p> <p><font size="2">by writing these two lines you can sort the data into dataview sorting data into dataview is fast and easer</p> </font> 2008-01-16T12:12:06-05:002112908http://forums.asp.net/p/1206311/2112908.aspx/1?Re+How+to+sort+data+into+GridViewRe: How to sort data into GridView <p>&nbsp;hi,</p> <p>&nbsp; </p> <p>Reload teh dataview by sorting the dataset/Datatable with the clicked value.</p> <p>or change teh view to Grid and again reload at every time with the sorting colum header/adn default column header .<br> </p> <p>&nbsp;</p> <p>&nbsp;&nbsp;</p> 2008-01-16T13:52:51-05:002122062http://forums.asp.net/p/1206311/2122062.aspx/1?Re+How+to+sort+data+into+GridViewRe: How to sort data into GridView <pre><span style="color:rgb(0,0,0)"></span><span style="color:rgb(0,0,255)">public</span><span style="color:rgb(0,0,0)"> DataTable GetTable()<br> {<br> </span><span style="color:rgb(0,0,255)">string</span><span style="color:rgb(0,0,0)"> connectionString </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">&quot;</span><span style="color:rgb(0,128,128)">...Northwind...</span><span style="color:rgb(0,0,0)">&quot;</span><span style="color:rgb(0,0,0)">;<br> DataTable customers </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,255)">new</span><span style="color:rgb(0,0,0)"> DataTable(</span><span style="color:rgb(0,0,0)">&quot;</span><span style="color:rgb(0,128,128)">Customers</span><span style="color:rgb(0,0,0)">&quot;</span><span style="color:rgb(0,0,0)">);<br><br> </span><span style="color:rgb(0,0,255)">using</span><span style="color:rgb(0,0,0)"> (SqlConnection connection </span><span style="color:rgb(0,0,0)">=<br> </span><span style="color:rgb(0,0,255)">new</span><span style="color:rgb(0,0,0)"> SqlConnection(connectionString))<br> {<br> SqlCommand selectAllCustomers </span><span style="color:rgb(0,0,0)">=<br> </span><span style="color:rgb(0,0,0)">connection.CreateCommand();<br> selectAllCustomers.CommandText </span><span style="color:rgb(0,0,0)">=<br> </span><span style="color:rgb(0,0,0)">&quot;</span><span style="color:rgb(0,128,128)">SELECT * FROM [Customers]</span><span style="color:rgb(0,0,0)">&quot;</span><span style="color:rgb(0,0,0)">;<br><br> connection.Open();<br> customers.Load(selectAllCustomers.ExecuteReader<br> (CommandBehavior.CloseConnection));<br> }<br><br> </span><span style="color:rgb(0,0,255)">return</span><span style="color:rgb(0,0,0)"> customers;</span></pre> <pre><span style="color:rgb(0,0,0)"><br> }</span></pre> <p>&nbsp;</p> <pre><span style="color:rgb(0,0,0)"></span><span style="color:rgb(0,0,255)">private</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,255)">void</span><span style="color:rgb(0,0,0)"> Form1_Load(</span><span style="color:rgb(0,0,255)">object</span><span style="color:rgb(0,0,0)"> sender, EventArgs e)<br> {<br> dataGridView1.DataSource </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(0,0,0)"> GetTable().DefaultView;</span></pre> <pre><span style="color:rgb(0,0,0)"> dv.Sort </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">&quot;</span><span style="color:rgb(0,128,128)">Name ASC</span><span style="color:rgb(0,0,0)">&quot;</span><span style="color:rgb(0,0,0)">;<br> dataGridView1.DataSource </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(0,0,0)"> dv;</span><span style="color:rgb(0,0,0)"><br> }</span></pre> <pre>&nbsp;</pre> <pre>-------------------</pre> <pre>I hope this will help you&nbsp;</pre> 2008-01-21T11:35:40-05:002123660http://forums.asp.net/p/1206311/2123660.aspx/1?Re+How+to+sort+data+into+GridViewRe: How to sort data into GridView <p>Please note, your sorting will be effective only if you select the PrimaryKey Item in your query string.</p> <p>KBN Sarma</p> 2008-01-22T04:06:23-05:002126509http://forums.asp.net/p/1206311/2126509.aspx/1?Re+How+to+sort+data+into+GridViewRe: How to sort data into GridView <p>Sorting can be performed quite well even if you do not select the PrimaryKey Item in your query string.</p> <p>Any of the data columns can be effectively sorted on.</p> 2008-01-23T04:29:06-05:002126533http://forums.asp.net/p/1206311/2126533.aspx/1?Re+How+to+sort+data+into+GridViewRe: How to sort data into GridView <p>Thank you for your information.&nbsp;&nbsp; Earlier I tried, but it gave some problems.</p> <p>Regards, KBN Sarma</p> 2008-01-23T04:45:06-05:002149301http://forums.asp.net/p/1206311/2149301.aspx/1?Re+How+to+sort+data+into+GridViewRe: How to sort data into GridView <p>using</p> <font size="2">System;</font><font color="#0000ff" size="2"> </font><font color="#0000ff" size="2"> <p>using</p> </font><font size="2">System.Data;</font><font color="#0000ff" size="2"> </font><font color="#0000ff" size="2"> <p>using</p> </font><font size="2">System.Configuration;</font><font color="#0000ff" size="2"> </font><font color="#0000ff" size="2"> <p>using</p> </font><font size="2">System.Collections;</font><font color="#0000ff" size="2"> </font> <font color="#0000ff" size="2"> <p>using</p> </font><font size="2">System.Web;</font><font color="#0000ff" size="2"> </font><font color="#0000ff" size="2"> <p>using</p> </font><font size="2">System.Web.Security;</font><font color="#0000ff" size="2"> </font> <font color="#0000ff" size="2"> <p>using</p> </font><font size="2">System.Web.UI;</font><font color="#0000ff" size="2"> </font> <font color="#0000ff" size="2"> <p>using</p> </font><font size="2">System.Web.UI.WebControls;</font><font color="#0000ff" size="2"> </font><font color="#0000ff" size="2"> <p>using</p> </font><font size="2">System.Web.UI.WebControls<wbr>.WebParts;</font><font color="#0000ff" size="2"> </font><font color="#0000ff" size="2"> <p>using</p> </font><font size="2">System.Web.UI.HtmlControls;</font><font color="#0000ff" size="2"> </font><font color="#0000ff" size="2"> <p>using</p> </font><font size="2">System.Data.SqlClient;</font><font color="#0000ff" size="2"> </font><font color="#0000ff" size="2"> <p>public</p> </font><font size="2"></font><font color="#0000ff" size="2">partial</font><font size="2"> </font><font color="#0000ff" size="2">class</font><font size="2"> </font><font color="#008080" size="2">treenrepeater </font><font size="2">: System.Web.UI.</font><font color="#008080" size="2">Page</font><font size="2"> </font><font size="2"> <p>{</p> <p>&nbsp;</p> </font><font color="#008080" size="2">SqlConnection</font><font size="2"> con = </font> <font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">SqlConnection</font><font size="2"> (</font><font color="#008080" size="2">ConfigurationManager</font><font size="2">.AppSettings[</font><font color="#800000" size="2">&quot;conn&quot;</font><font size="2">]); </font><font size="2"> <p>&nbsp;</p> </font><font color="#008080" size="2">SqlDataAdapter</font><font size="2"> da; </font> <font size="2"> <p>&nbsp;</p> </font><font color="#008080" size="2">DataSet</font><font size="2"> ds; </font><font size="2"> <p>&nbsp;</p> </font><font color="#0000ff" size="2">protected</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> Page_Load(</font><font color="#0000ff" size="2">object</font><font size="2"> sender, </font><font color="#008080" size="2">EventArgs</font><font size="2"> e) </font><font size="2"> <p>{</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">if</font><font size="2"> (!IsPostBack) </font> <font size="2"> <p>{</p> <p>&nbsp;</p> <p>tree();</p> <p>rep();</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">int</font><font size="2"> a = 9; </font><font size="2"> <p>Response.Write(a);</p> <p>grd();</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>}</p> <p>&nbsp;</p> <p>}</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">static</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> Main(</font><font color="#0000ff" size="2">string</font><font size="2">[] args) </font><font size="2"> <p>{ }</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> tree() </font><font size="2"> <p>{</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">string</font><font size="2"> s = </font><font color="#800000" size="2">&quot;select * from category&quot;</font><font size="2">; </font><font size="2"> <p>da = </p> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">SqlDataAdapter</font><font size="2">(s, con); </font><font size="2"> <p>ds = </p> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">DataSet</font><font size="2">(); </font><font size="2"> <p>da.Fill(ds, </p> </font><font color="#800000" size="2">&quot;s&quot;</font><font size="2">); </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//TreeView1.Parent = &quot;f&quot;;</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#0000ff" size="2">foreach</font><font size="2"> (</font><font color="#008080" size="2">DataRow</font><font size="2"> dr </font><font color="#0000ff" size="2">in</font><font size="2"> ds.Tables[ </font> <font color="#800000" size="2">&quot;s&quot;</font><font size="2">].Rows) </font><font size="2"> <p>{</p> <p>&nbsp;</p> </font><font color="#008080" size="2">TreeNode</font><font size="2"> tr = </font> <font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">TreeNode</font><font size="2">(dr[</font><font size="3"> </font><font color="#800000" size="2">&quot;category_name&quot;</font><font size="2">].ToString()); </font><font size="2"> <p>TreeView1.Nodes.Add(tr);</p> <p>&nbsp;</p> </font><font color="#008000" size="2">//string str=&quot;select sub_cat_name from sub_category where cat_id=(select cat_id from category where category_name='&quot;&#43;TreeView1<wbr>.SelectedNode.Value&#43;&quot;')&quot;; </font><font size="2"></font><font size="2"> <p>&nbsp;</p> </font><font color="#0000ff" size="2">string</font><font size="2"> str = </font><font color="#800000" size="2">&quot;select * from sub_category where cat_id='&quot;</font><font size="2"> &#43; dr[</font><font color="#800000" size="2"> &quot;cat_id&quot;</font><font size="2">].ToString() &#43; </font><font color="#800000" size="2">&quot;'&quot;</font><font size="2">; </font><font size="2"> <p>da = </p> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">SqlDataAdapter</font><font size="2">(str, con); </font><font size="2"> <p>ds = </p> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">DataSet</font><font size="2">(); </font><font size="2"> <p>da.Fill(ds, </p> </font><font color="#800000" size="2">&quot;aa&quot;</font><font size="2">); </font><font size="2"> <p>&nbsp;</p> </font><font color="#0000ff" size="2">foreach</font><font size="2"> (</font><font color="#008080" size="2">DataRow</font><font size="2"> dd </font><font color="#0000ff" size="2">in</font><font size="2"> ds.Tables[ </font> <font color="#800000" size="2">&quot;aa&quot;</font><font size="2">].Rows) </font><font size="2"> <p>{</p> <p>&nbsp;</p> </font><font color="#008080" size="2">TreeNode</font><font size="2"> t1 = </font> <font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">TreeNode</font><font size="2">(dd[</font><font size="3"> </font><font color="#800000" size="2">&quot;sub_cat_name&quot;</font><font size="2">].ToString()); </font><font size="2"> <p>tr.ChildNodes.Add(t1);</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">string</font><font size="2"> ss = </font><font color="#800000" size="2">&quot;select * from product where sub_cat_id='&quot;</font><font size="2"> &#43; dd[</font><font color="#800000" size="2"> &quot;sub_cat_id&quot;</font><font size="2">] &#43; </font><font color="#800000" size="2">&quot;'&quot;</font><font size="2">; </font><font size="2"> <p>da = </p> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">SqlDataAdapter</font><font size="2">(ss, con); </font><font size="2"> <p>ds = </p> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">DataSet</font><font size="2">(); </font><font size="2"> <p>da.Fill(ds, </p> </font><font color="#800000" size="2">&quot;as&quot;</font><font size="2">); </font><font size="2"> <p>&nbsp;</p> </font><font color="#0000ff" size="2">foreach</font><font size="2"> (</font><font color="#008080" size="2">DataRow</font><font size="2"> df </font><font color="#0000ff" size="2">in</font><font size="2"> ds.Tables[ </font> <font color="#800000" size="2">&quot;as&quot;</font><font size="2">].Rows) </font><font size="2"> <p>{</p> <p>&nbsp;</p> </font><font color="#008080" size="2">TreeNode</font><font size="2"> t2 = </font> <font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">TreeNode</font><font size="2">(df[</font><font size="3"> </font><font color="#800000" size="2">&quot;product_name&quot;</font><font size="2">].ToString()); </font><font size="2"> <p>t1.ChildNodes.Add(t2);</p> <p>}</p> <p>}</p> <p>&nbsp;</p> </font><font color="#008000" size="2">//TreeView1.DataSource = ds.Tables[&quot;s&quot;];</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//TreeView1.DataBind();</font><font size="2"> </font><font size="2"> <p>}</p> <p>}</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> rep() </font><font size="2"> <p>{</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">string</font><font size="2"> s = </font><font color="#800000" size="2">&quot;select * from category&quot;</font><font size="2">; </font><font size="2"> <p>da = </p> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">SqlDataAdapter</font><font size="2">(s, con); </font><font size="2"> <p>ds = </p> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">DataSet</font><font size="2">(); </font><font size="2"> <p>da.Fill(ds, </p> </font><font color="#800000" size="2">&quot;s&quot;</font><font size="2">); </font><font size="2"> <p>Repeater1.DataSource = ds.Tables[</p> </font><font color="#800000" size="2">&quot;s&quot;</font><font size="2">]; </font><font size="2"> <p>Repeater1.DataBind();</p> <p>&nbsp;</p> </font><font color="#008000" size="2">//string st = &quot;select * from sub_category where cat_id='&quot;&#43;Repeater1&quot;;</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//da = new SqlDataAdapter(st, con);</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//ds = new DataSet();</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//da.Fill(ds, &quot;s&quot;);</font><font size="2"> </font> <font size="2"> <p>}</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">protected</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> CustomValidator1_ServerValidate<wbr>(</font><font color="#0000ff" size="2">object</font><font size="3"> </font><font size="2">source, </font><font color="#008080" size="2">ServerValidateEventArgs</font><font size="2"> args) </font><font size="2"> <p>{</p> <p>&nbsp;</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">if</font><font size="2"> (TextBox1.Text == </font> <font color="#800000" size="2">&quot;anish&quot;</font><font size="2">) </font><font size="2"> <p>{</p> <p>args.IsValid = </p> </font><font color="#0000ff" size="2">true</font><font size="2">; </font><font size="2"> <p>Response.Write(</p> </font><font color="#800000" size="2">&quot;abc&quot;</font><font size="2">); </font><font size="2"> <p>}</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">else</font><font size="2"> </font><font size="2"> <p>args.IsValid = </p> </font><font color="#0000ff" size="2">false</font><font size="2">; </font><font size="2"> <p>&nbsp;</p> <p>}</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">protected</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> Button1_Click(</font><font color="#0000ff" size="2">object</font><font size="2"> sender, </font><font color="#008080" size="2">EventArgs</font><font size="2"> e) </font><font size="2"> <p>{</p> <p>&nbsp;</p> </font><font color="#008000" size="2">//Response.Write(TextBox1.Text);</font><font size="2"> </font><font size="2"> <p>}</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">protected</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> Button1_Click1(</font><font color="#0000ff" size="2">object</font><font size="2"> sender, </font><font color="#008080" size="2">EventArgs</font><font size="2"> e) </font><font size="2"> <p>{</p> <p>&nbsp;</p> <p>Response.Redirect(</p> </font><font color="#800000" size="2">&quot;default.aspx?a=&quot;</font><font size="2">&#43;TextBox1.Text); </font><font size="2"> <p>}</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> grd() </font><font size="2"> <p>{</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">string</font><font size="2"> s = </font><font color="#800000" size="2">&quot;select * from product&quot;</font><font size="2">; </font><font size="2"> <p>da = </p> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">SqlDataAdapter</font><font size="2">(s, con); </font><font size="2"> <p>ds = </p> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">DataSet</font><font size="2">(); </font><font size="2"> <p>da.Fill(ds, </p> </font><font color="#800000" size="2">&quot;s&quot;</font><font size="2">); </font><font size="2"> <p>&nbsp;</p> <p>&nbsp;</p> <p>GridView1.DataSource = ds.Tables[</p> </font><font color="#800000" size="2">&quot;s&quot;</font><font size="2">]; </font><font size="2"> <p>GridView1.DataBind();</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>}</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">protected</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> GridView1_Sorting(</font><font color="#0000ff" size="2">object</font><font size="2"> sender, </font><font color="#008080" size="2">GridViewSortEventArgs</font><font size="2"> e) </font><font size="2"> <p>{</p> <p>&nbsp;</p> </font><font color="#008000" size="2">//string s = GridView1.SortExpression;</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//e.SortExpression = s;</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008080" size="2">SqlDataAdapter</font><font size="2"> da1 = </font> <font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">SqlDataAdapter</font><font size="2"> (</font><font color="#800000" size="2">&quot;Select * from product&quot;</font><font size="2">,con); </font><font size="2"> <p>&nbsp;</p> </font><font color="#008080" size="2">DataTable</font><font size="2"> dt = </font> <font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">DataTable</font><font size="2">(); </font><font size="2"> <p>&nbsp;</p> <p>da1.Fill(dt);</p> <p>&nbsp;</p> </font><font color="#008080" size="2">DataView</font><font size="2"> dv = </font> <font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#008080" size="2">DataView</font><font size="2">(dt); </font><font size="2"> <p>&nbsp;</p> <p>&nbsp;</p> </font><font color="#008000" size="2">//dv.Sort</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">// GridView1.DataSource = dv.Sort;</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//GridView1.DataBind();</font><font size="2"> </font><font size="2"> <p>dv.Sort = e.SortExpression &#43; </p> </font><font color="#800000" size="2">&quot; &quot;</font><font size="2"> &#43; </font><font color="#800000" size="2">&quot;ASC&quot;</font><font size="2">; </font><font size="2"> <p>GridView1.DataSource = dv;</p> <p>GridView1.DataBind();</p> <p>&nbsp;</p> </font><font color="#008000" size="2">//string s = GridView1.SortExpression;</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//string r = e.SortExpression;</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//if (s.IndexOf(r) &lt; 0)</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//{</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">// if (r.Length &gt; 0)</font><font size="2"> </font> <font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">// {</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">// e.SortExpression = r &#43; &quot;,&quot; &#43; s;</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">// }</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">// else</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">// {</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">// e.SortExpression = r;</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">// }</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//}</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//else</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//{</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">// e.SortExpression = s;</font><font size="2"> </font><font size="2"> <p>&nbsp;</p> </font><font color="#008000" size="2">//} </font><font size="2"></font><font size="2"> <p>}</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">protected</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> GridView1_SelectedIndexChanged(</font><font color="#0000ff" size="2">object</font><font size="3"> </font><font size="2">sender, </font><font color="#008080" size="2">EventArgs</font><font size="2"> e) </font><font size="2"> <p>{</p> <p>}</p> <p>}</p> </font> 2008-02-02T10:02:05-05:002167386http://forums.asp.net/p/1206311/2167386.aspx/1?Re+How+to+sort+data+into+GridViewRe: How to sort data into GridView <p>Hi,</p> <p>You can enable the sorting to true in design mode of gridview. Also for each boundfield, provide a sort expression. Now depending on the sorting expression you can query the database.</p> 2008-02-12T05:17:37-05:002169909http://forums.asp.net/p/1206311/2169909.aspx/1?Re+How+to+sort+data+into+GridViewRe: How to sort data into GridView <p>To Sort the Items in asp.net data grid double click on the title tag. It will be get sorted. </p> 2008-02-13T05:47:17-05:002191257http://forums.asp.net/p/1206311/2191257.aspx/1?Re+How+to+sort+data+into+GridViewRe: How to sort data into GridView <p>Is it so much difficult to implement sorting in GridView? Anyways, I think you can just use &quot;sorting=True&quot; in the properties of the gridview.&nbsp;</p> <p>Sorry if my understanding is wrong on this query....&nbsp;</p> 2008-02-23T05:26:00-05:002191270http://forums.asp.net/p/1206311/2191270.aspx/1?Re+How+to+sort+data+into+GridViewRe: How to sort data into GridView <p>While fetching ur data from data base try to add OrderBy Asceding or descending clause with ur select sattement.</p> <p>hope this helps</p> <p>sam</p> 2008-02-23T05:38:12-05:002975997http://forums.asp.net/p/1206311/2975997.aspx/1?Re+How+to+sort+data+into+GridViewRe: How to sort data into GridView <p>how to sort data when the columns are dynamically generated at runtime .sorting when done to . its possible to sort in one direction but suppose we hav made it ascending how do we make it descending on the next click on header. please give a full working&nbsp; example .as i have tried many options but somehow it's not working fine. also sorting&nbsp; direction and criteria should be maintained across all pages of the data gridview. take a&nbsp; gridview data of simple&nbsp;3 columns and therir headers are not&nbsp;harcoded but rather dynamically created.&nbsp;Please give a working solution. i'm stuck&nbsp;</p> 2009-03-02T08:18:43-05:00