473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

GridView Sorting problem

8
I have Table News
NewsID, int
NewsHeadLint, varcahr(200)
OrderNews, int

I gridView Display as following query
Select ID,NewsHeadLine from News order By OrderNews DESC
----
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="NewsID" EmptyDataText="There are no data records to display."
DataSourceID="SqlDataSource1" Style="position: relative; left: 4px; top: 44px;" OnRowCommand="Grid1_Command" AllowPaging="True" PageSize="8" Width="571px" >
I have Add in gridView 2 buttonField
<asp:ButtonField ButtonType="Image" CommandName="CmdUp"..
<asp:ButtonField ButtonType="Image" CommandName="CmdDown"
..
CmdUP(command up) get the value of current order row and row the above in gridView and
swtich between them
In CS code
protected void Grid1_Command(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{

// Object o = sender;


String z = (String)e.CommandArgument;

int indexGrid = Convert.ToInt16(z);
String CommandNamew = e.CommandName.ToString();
switch (CommandNamew)
{
//-------------------------------------------


case "CmdUp":
{

//I have write query and correctly excute in Database




String NewsIDcurrent = GridView1.DataKeys[indexGrid].Value.ToString().Trim(); //IDnews
//Response.Write(GridView1.DataKeys[Convert.ToInt16 (z)].Values[0].ToString());

SqlCommand Cmd = new SqlCommand();
Cmd.Connection = conn;




if ((indexGrid + 1) != GridView1.DataKeys.Count)
{

//NewsIDvalue this the current Id
String NewsIDunder = GridView1.DataKeys[indexGrid + 1].Value.ToString().Trim();
try
{
conn.Open();
//---Current
Cmd.CommandText = "Select OrderNews from News where NewsID=" + NewsIDcurrent;
int orderVal = (int)Cmd.ExecuteScalar();


Cmd.Parameters.Clear();



Cmd.CommandText = "Select OrderNews from News where NewsID=" + NewsIDunder;

int orderUnder = (int)Cmd.ExecuteScalar();
Cmd.Parameters.Clear();

Cmd.CommandText = "update News Set OrderNews=" + Convert.ToString(orderUnder) + " where NewsID=" + NewsIDcurrent;
Cmd.ExecuteNonQuery();

//--Under
Cmd.Parameters.Clear();


Cmd.CommandText = "update News Set OrderNews=" + Convert.ToString(orderVal) + " where NewsID=" + NewsIDunder;
Cmd.ExecuteNonQuery();



Cmd.Parameters.Clear();


// GridView1.DataBind();
}

catch (Exception ex)
{

}

finally
{
conn.Close();
// Response.Redirect("NewsCollection.aspx"); with it or without it
}






}

break;
}//end cmddown


case "CmdDown":
{


//I have write query and correctly excute in Database same idea as above

break;


}
default: { break; }

............




I have problem with this command(excute twice,or not display modefection unless u refresh the browser...)
what excatly best way to write and what event I must to write in the webpage(_Load _preRender..)
Jun 13 '07 #1
0 1285

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
5
by: yefei | last post by:
In my web design, I display records from a SQL DataBase according to some filters the GridView is defined with select commands and selest parameters however, I also want to display all records...
4
by: samb | last post by:
When I use manual databinding to a GridView control, as bellow. 'Retrive a DataSet from database Dim ds As DataSet = uda.GetUsers(conectionString) 'gvUsers - The GridView gvUsers.DataSource...
4
by: kurt sune | last post by:
I have a an aspx page with a gridview. The gridview is data bound to a generic list of custom classes. The gridview's DataSource is thus not set. Now I want to add sorting to it. So I create...
0
by: jobo | last post by:
Hey there, I'm having a problem getting sorting to work. Here's what the GridView looks like: "server" ID="updt1" Mode="Conditional">
12
by: Cindy Lee | last post by:
When I do a sorta on 1 table, then the other table goes back to the original order. What can I set so, it keeps the order of the other current gridview's order. I set all the gridview values...
4
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is returned from a function. The definitions in the function are: Dim ReportDS As DataSet = New DataSet Dim...
2
by: mahesh123 | last post by:
Hi, I am using gridview in my form and binded the gridview with object datasource.I am trying to implement sorting for my grid view and i am getting following error.i am using asp.net with VB ...
0
by: Sobin Thomas | last post by:
Hi All, How can I bind the Gridview control to Sql Datasource control on a button click(I see majority of the articles binding datasource at page load) I need to enable the paging and sorting of...
1
by: Sobin Thomas | last post by:
Hi All, How can I bind the Gridview control to Sql Datasource control on a button click(I see majority of the articles binding datasource at page load) I need to enable the paging and sorting of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.