|
I have GridView
using table in DB
i added <asp:ButtonField command Name:cmdUp
the command excute correctly in DataBase
but the problem its excute twice
.....
protected void Grid1_Command(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
switch (CommandName)
{
//-------------------------------------------
case "cmdUp":
{
GridView1.DataBind();
break;
}//End Up
aj123
-- modified at 4:17 Wednesday 20th June, 2007
|
|
|
|
|
The code seems right but it is better to send the other code blocks to be examined.
|
|
|
|
|
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();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["colliersUAEConnectionString"].ConnectionString.ToString());
switch (CommandNamew)
{
//-------------------------------------------
case "CmdUp":
{
String NewsIDcurrent = GridView1.DataKeys[indexGrid].Value.ToString().Trim(); //IDnews
//Response.Write(GridView1.DataKeys[Convert.ToInt16 (z)].Values[0].ToString());
System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand();
System.Data.SqlClient.SqlCommand acmd = new System.Data.SqlClient.SqlCommand();
acmd.Connection = conn;
Cmd.Connection = conn;
// Label2.Text = NewsIDvalue;
//conn.Open();
//String orderVal = (String)Cmd.ExecuteScalar();
if (indexGrid != 0)
{
try
{
//NewsIDvalue this the current Id
String NewsIDAbove = GridView1.DataKeys[indexGrid - 1].Value.ToString().Trim();
conn.Open();
//---Current
Cmd.CommandText = "Select OrderNews from zNews where NewsID=" + NewsIDcurrent;
int orderVal = (int)Cmd.ExecuteScalar();//above
// orderVal = orderVal + 1;
Cmd.Parameters.Clear();
Cmd.CommandText = "select OrderNews from zNews where NewsID=" + NewsIDAbove;
int orderAbove = (int)Cmd.ExecuteScalar();
Cmd.Parameters.Clear();
Cmd.CommandText = "update zNews Set OrderNews=" + Convert.ToString(orderAbove) + " where NewsID=" + NewsIDcurrent;
Cmd.ExecuteNonQuery();
Cmd.Parameters.Clear();
//--Above
Cmd.Parameters.Clear();
Cmd.Dispose();
// acmd.CommandText = "Select OrderNews from News where NewsID=" + NewsIDAbove;
// acmd.Parameters.Clear();
acmd.CommandText = "update zNews Set OrderNews=" + Convert.ToString(orderVal) + " where NewsID=" + NewsIDAbove;
acmd.ExecuteNonQuery();
acmd.Parameters.Clear();
acmd.Dispose();
}
catch (Exception ex)
{
}
finally
{
GridView1.DataBind();
conn.Close();
//Response.Redirect("NewsCollection.aspx");
}
//Page.DataBind();
}
break;
}//End Up
default: { break; }
}//end switch
}
------------------
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:colliersUAEConnectionString %>"
SelectCommand="SELECT NewsID, HeadLine, Visablity, SUBSTRING(CAST(Date AS varchar(12)), 1, 11) AS 'Date', HomePage, OrderNews FROM zNews Order By OrderNews Desc" UpdateCommand="UPDATE News SET Visablity = @visP WHERE (NewsID = @NewsIDP)">
<UpdateParameters>
<asp:Parameter Name="visP" />
<asp:Parameter Name="NewsIDP" />
</UpdateParameters>
</asp:SqlDataSource>
--------------------
<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: -2px;" OnRowCommand="Grid1_Command" AllowPaging="True" PageSize="8" Width="688px" OnRowUpdated="Grid1_RowUpdated" CellPadding="4" ForeColor="#333333" GridLines="None" HorizontalAlign="Center" >
<Columns>
<asp:ButtonField ButtonType="Image" CommandName="CmdUp" HeaderText="Up" ImageUrl="~/Images/btnUp.gif" />
--------------------
aj123
|
|
|
|
|
protected void Grid1_Command(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
String z = (String)e.CommandArgument;
int indexGrid = Convert.ToInt16(z);
String CommandNamew = e.CommandName.ToString();
SqlConnection conn = new SqlConnection--
switch (CommandNamew)
{
//-------------------------------------------
case "CmdUp":
{
String NewsIDcurrent = GridView1.DataKeys[indexGrid].Value.ToString().Trim();
System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand();
System.Data.SqlClient.SqlCommand acmd = new System.Data.SqlClient.SqlCommand();
acmd.Connection = conn;
Cmd.Connection = conn;
//String orderVal = (String)Cmd.ExecuteScalar();
if (indexGrid != 0)
{
try
{
String NewsIDAbove = GridView1.DataKeys[indexGrid - 1].Value.ToString().Trim();
conn.Open();
//---Current
Cmd.CommandText = "Select OrderNews from zNews where NewsID=" + NewsIDcurrent;
int orderVal = (int)Cmd.ExecuteScalar();//above
// orderVal = orderVal + 1;
Cmd.Parameters.Clear();
Cmd.CommandText = "select OrderNews from zNews where NewsID=" + NewsIDAbove;
int orderAbove = (int)Cmd.ExecuteScalar();
Cmd.Parameters.Clear();
Cmd.CommandText = "update zNews Set OrderNews=" + Convert.ToString(orderAbove) + " where NewsID=" + NewsIDcurrent;
Cmd.ExecuteNonQuery();
Cmd.Parameters.Clear();
//--Above
Cmd.Parameters.Clear();
Cmd.Dispose();
// acmd.CommandText = "Select OrderNews from News where NewsID=" + NewsIDAbove;
// acmd.Parameters.Clear();
acmd.CommandText = "update zNews Set OrderNews=" + Convert.ToString(orderVal) + " where NewsID=" + NewsIDAbove;
acmd.ExecuteNonQuery();
acmd.Parameters.Clear();
acmd.Dispose();
}
catch (Exception ex)
{
}
finally
{
GridView1.DataBind();
conn.Close();
//Response.Redirect("NewsCollection.aspx");
}
//Page.DataBind();
}
break;
}//End Up
default: { break; }
}//end switch
}
------------------
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:colliersUAEConnectionString %>"
SelectCommand="SELECT NewsID, HeadLine, Visablity, SUBSTRING(CAST(Date AS varchar(12)), 1, 11) AS 'Date', HomePage, OrderNews FROM zNews Order By OrderNews Desc" UpdateCommand="UPDATE News SET Visablity = @visP WHERE (NewsID = @NewsIDP)">
<UpdateParameters>
<asp:Parameter Name="visP" />
<asp:Parameter Name="NewsIDP" />
</UpdateParameters>
</asp:SqlDataSource>
--------------------
<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: -2px;" OnRowCommand="Grid1_Command" AllowPaging="True" PageSize="8" Width="688px" OnRowUpdated="Grid1_RowUpdated" CellPadding="4" ForeColor="#333333" GridLines="None" HorizontalAlign="Center" >
<Columns>
<asp:ButtonField ButtonType="Image" CommandName="CmdUp" HeaderText="Up" ImageUrl="~/Images/btnUp.gif" />
--------------------
aj123
|
|
|
|
|
Hello,
Can any one guide me know to disable back button in FireFox browser. For IE i am using the following code to disable browser back button.
<script type="text/javascript" language="javascript">
javascript: window.history.forward(1);
</script>
Its not working in FireFox browser.
Plz Help.
Dhulipudi
|
|
|
|
|
What you want to achieve by doing this ?
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
|
Hi Sylvester
How the job is going in Mumbai ? Did you get the rid of hot wheather or its same as like summner
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
My job is going well. How about you and your job?
Here its raining now. So the weather is good. Night its very cold.
I am enjoying the rain
Regards,
Sylvester G
sylvester_g_m@yahoo.com
|
|
|
|
|
Life is going Cool
Don't have much work now a days so enjoying CP
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
hello sir,
function validation()
{
windows.History.go[-1];
}
use that command it will work.
It works only if there is request pages.
byee
All the best
Murali
|
|
|
|
|
Is it a good idea playing with client browser ?
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Thank you Murali,
I will try it.
Regards,
JJ
|
|
|
|
|
Hi all,
I have a data grid in my aspx page and i want to display only 5 record at a time. that i can do with the help of page size. but I want the gridview to move to next page after 30 seconds without any user interection. after all the data has been shown ( at last page ) i want the page to redirect to my home page.
can anyone have an idea?
thanks in advance
|
|
|
|
|
I'm using ASP.net 2.0 with AJAX enabled. Just for you'r information
|
|
|
|
|
hi, I have a dropdownlist which is binded with data from the database i use the sqldatasource, but it is too long as simliar entries are shown. How do I remove duplicate entries in the dropdownlist? please advice. thanks.
|
|
|
|
|
Hi,
You should provide select query with "DISTINCT" funtion in the "SelectCommand" property of your SQLDataSource as following.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Connstring"
SelectCommand="select distinct(ProductID) from Products"></asp:SqlDataSource>
I hope this will help you.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
hi. it works. thanks a lot. Hope u don mind i ask qns here cos i am a slow learner. i am reading books on asp.net. thanks a lot 4 ur help
|
|
|
|
|
Hello people,
I have a system with a windows application, a web service and a remoting application (on another machine.)
The windows application calls the web service to execute some task. The web service references an assembly that will establish contact with the remoting server to execute the task. Everything works fine but if an exception is thrown by the remoting server, I am not able to propagate it back to the remoting client (web service.)
The error is:
Server encountered an internal error. For more information, turn on customErrors in the server's .config file.
Does "server" here mean the web service or the remoting server? I have added the following lines at the end of the web.config of the web service:
<system.runtime.remoting>>
<debug loadTypes="true" />
<customErrors mode="off" />
</system.runtime.remoting>
I tried both "on" and "off" for the customErrors but nothing works.
To test this issue, I have deliberately sent corrupted data to the remoting server in order to get an exception. I am using .NET 1.1.
In the remoting object method (the one that is called from the web service) I placed a try-catch and displayed the exception in the console (the remoting server is a console app) and I also rethrew a new application exception back. The console writes the correct exception message but it seems that the throw doesn't propagate back the exception message.
I can always get around the problem by adding a flag property and an exception message property in the remoting object. I would then catch the exception in the remoting object, set the flag to false and the message to the exception message and return. Back on the web service, I would test if the flag is false and continue from there.
I would prefer to be able to propagate the exception in a clean manner so if anyone has any clue, I would appreciate it.
Thanks,
Talal
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
Hi, I'm atempting to prevent SQL injection by incorporating the function below into my code, but I'm not sure how to change my select statement to make it work. Below is the function I'm intending to use and below it is my code.
function killChars(strWords)
dim badChars
dim newChars
badChars = array("select", "drop", ";", "--", "insert", "delete", "xp_")
newChars = strWords
for i = 0 to uBound(badChars)
newChars = replace(newChars, badChars(i), "")
next
killChars = newChars
end function
Private Sub lblRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblRegister.Click
Dim myConnection As OdbcConnection
Dim myCommand As OdbcCommand
Dim strInsert As String
Dim strSQL As String
strSQL = String.Empty
myConnection = New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=myServer;Database=myDB;User=myUser; Password=myPW;Option=3;")
strSQL = String.Format("SELECT UserName FROM myTable WHERE (UserName='{0}');", txtUserName.Text)
myCommand = New OdbcCommand(strSQL, myConnection)
myCommand.CommandType = CommandType.Text
myConnection.Open()
Dim result As Integer = CType(myCommand.ExecuteScalar,Integer)
' If record count > 0, then UserName already exists in the database
If result > 0 Then
lblMessage.Text = "User name already exists in the database"
Else
strInsert = "INSERT into myTable (Password,UserName)values (?,?)"
Dim myCommand1 As OdbcCommand = New OdbcCommand(strInsert, myConnection)
myCommand1.Parameters.Add(new OdbcParameter("@Password", txtPassword.Text))
myCommand1.Parameters.Add(new OdbcParameter("@UserName", txtUserName.Text))
Dim result1 As Integer = myCommand1.ExecuteNonQuery()
End If
'close the connection
myConnection.Close()
End Sub
I don't know how to modify the lines
strSQL = String.Format("SELECT UserName FROM myTable WHERE (UserName='{0}');", txtUserName.Text)
and
strInsert = "INSERT into myTable (Password,UserName)values (?,?)"
to make the KillChars function work. Any suggestions will be grately appreciated, thank you in advance for your help.
-- modified at 3:07 Wednesday 20th June, 2007
|
|
|
|
|
ASPnoob wrote: I don't know how to modify the line
strSQL = String.Format("SELECT UserName FROM myTable WHERE (UserName='{0}');", txtUserName.Text)
to make the KillChars function work.
You can use the killChars like this:
strSQL = String.Format("SELECT UserName FROM myTable WHERE (UserName='{0}');", killChars(txtUserName.Text))
But you should use killChars to prevent SQL Injection.
The best way you can do this is by using stored procedure.
I would suggest you to read this http://www.codeproject.com/cs/database/SqlInjectionAttacks.asp[^].
Regards,
Arun Kumar.A
|
|
|
|
|
I could be wrong on this but I thought the whole point of using parameters (as you are doing) was to prevent SQL injection, ie ADO.NET would take care of it for you so you wouldn't need your own function.
|
|
|
|
|
|
hi friends
i have textbox .how can i pass another page in textbox value using querystring through javascript
this my javascript snipt
onclick=\"yih_idpop('check.aspx?');
how to add here in my textbox
regards
saravanan
|
|
|
|
|
you can do it in serverside code
Response.Redirect("'check.aspx?QueryString1=" + TextBox1.Text);
Regards,
Sylvester G
sylvester_g_m@yahoo.com
|
|
|
|