|
hi
i have a gridview.
i am filling gridview through a view,
i am inserting a record through a storedprocedure and
i want to display the last inserted record as a last record and also i want to highlight the record as well as focus on the newly inserted record.
provide code for this one..
Koti
|
|
|
|
|
Assuming your first row of gridview is the last inserted record
in design mode provide backcolor in SelectedRowStyle or in your CSS.
then in ur insert function after Binding gridview write the below line
gridview1.SelectedIndex = 0;
|
|
|
|
|
The Code
In order to run the code below, you must first set up Membership. The simplest way to do this is to simply add to your web.config a very small section enabling RoleManager. This will automatically create the membership database in sqlexpress. You should probably add a couple users just so your gridview is not empty from the start. The code you need to add to an empty asp.net 2.0 web site project is as follows (put it in the <System.Web> section).
<roleManager enabled=“true“></roleManager>
Once you have done that, you can copy the code below to a new web page and simply run it.
Briefly, the way the code works is that when a row is inserted into the database the sqldatasource’s Inserted event is called. In this event, we take a look at the return parameter which comes from the sql:
InsertCommand=”INSERT INTO [Names] ([name]) VALUES (@name);SELECT @NewID = Scope_Identity()”
NewId is actually a return parameter, so we can get that back in the inserted event. Once we get the value back, we store it in viewstate so that on the upcoming page_prerender, we can check and see which row has that id in it, and then highlight that row. The reason we do it in prerender and not load is because the inserted event is processed after load and it would not work if we put it there.
So, here is the code! Good luck.
<%@ Page Language=”C#” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<script runat=”server”>
// simple table named: Names. Two columns: id int, name varchar(64)
protected void ButtonInsert_Click(object sender, EventArgs e)
{
SqlDataSource1.InsertParameters["name"].DefaultValue = DateTime.Now.ToString();
int numInserted = SqlDataSource1.Insert();
GridView1.DataBind();
}
protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
object newId = e.Command.Parameters["@NewId"].Value;
ViewState["NewId"] = Convert.ToInt32(newId);
}
protected void Page_PreRender(object sender, EventArgs e)
{
string newIdLast = string.Empty;
if (ViewState["NewId"] != null)
{
int newId = (int)ViewState["NewId"];
newIdLast = newId.ToString();
int rowCnt = 0;
foreach (GridViewRow row in GridView1.Rows)
{
string newIdText = row.Cells[1].Text;
if (newIdText.Equals(newIdLast))
{
//GridView1.EditIndex = rowCnt;
//GridView1.SelectedIndex = rowCnt;
row.Attributes.Add(“bgcolor”, “Gray”);
break;
}
rowCnt++;
}
}
}
</script>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head id=”Head1″ runat=”server”>
<title>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<h2>Example of GridView that shows highlighted last inserted row</h2>
<br />
<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False” DataKeyNames=”id” DataSourceID=”SqlDataSource1″ >
<Columns>
<asp:CommandField ShowEditButton=”True” ShowDeleteButton=”True” />
<asp:BoundField DataField=”id” HeaderText=”id” InsertVisible=”False” ReadOnly=”True”
SortExpression=”id” />
<asp:BoundField DataField=”name” HeaderText=”name” SortExpression=”name” />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID=”SqlDataSource1″ runat=”server” ConnectionString=”<%$ ConnectionStrings:ConnectionString %>“
DeleteCommand=”DELETE FROM [Names] WHERE [id] = @id”
InsertCommand=”INSERT INTO [Names] ([name]) VALUES (@name);SELECT @NewID = Scope_Identity()”
SelectCommand=”SELECT [id], [name] FROM [Names]“ UpdateCommand=”UPDATE [Names] SET [name] = @name WHERE [id] = @id” OnInserted=”SqlDataSource1_Inserted”>
<DeleteParameters>
<asp:Parameter Name=”id” Type=”Int32″ />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name=”name” Type=”String” />
<asp:Parameter Name=”id” Type=”Int32″ />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name=”name” Type=”String” />
<asp:Parameter Direction=Output Name=”NewId” Size=4 Type=Int16 />
</InsertParameters>
</asp:SqlDataSource>
<br />
<br />
<asp:Button ID=”ButtonInsert” runat=”server” OnClick=”ButtonInsert_Click” Text=”Insert Record” /></div>
</form>
</body>
</html>
|
|
|
|
|
Hi
I have a textbox suppose if i enter like abcdefg (assume width is 100)
and
if i enter like abcdefghijklmnopqrstuvwxyz the width should be increased based on the input which i am providing.
how to solve, let me know the code for this one...
Koti
|
|
|
|
|
This will solve your problem to some extent:
<asp:TextBox ID="TextBox1" runat="server" onkeypress="return dWd(this);" onkeyup="return dWd2(this);" onkeydown="return dWd2(this);" Width="20"></asp:TextBox>
<script language="javascript">
function dWd(e)
{
var wt=parseInt(e.style.width);
wt+=10;
e.style.width=wt + "px";
}
function dWd2(e)
{
if(event.keyCode==8)
{
if(parseInt(e.style.width)>20)
{
var wt=parseInt(e.style.width);
wt-=10;
e.style.width=wt + "px";
}
}
}
</script>
CC26
|
|
|
|
|
|
Why to repost same question??????????????????????????????
himanshu
|
|
|
|
|
Please Don't Cross Post
|
|
|
|
|
I need to implement address verification system to my customer portal.
How can i implement it? I am new to it.... do we need some third party control? :
|
|
|
|
|
You'll need to buy third party software (or create a database with every possible address yourself but I doubt you'll want to do that. QAS is a popular product but it isn't cheap IIRC.
|
|
|
|
|
Inderjeet Kaur wrote: I need to implement address verification system to my customer portal.
How can i implement it? I am new to it.... do we need some third party control? :
You have came up with a bigger view of your problem ? What AVS will do ? What is the details requirements ? Did you tried anything ?
|
|
|
|
|
No abhijit, i was learning what AVS is? I have complete database with user credentials.
So, shall we implement it on our end?
What i learnt abt AVS is it returns some code by
checking all the numeric values from the address.....So can we do the implementation at our end?
Any help will be appreciated
modified on Friday, June 19, 2009 12:00 AM
|
|
|
|
|
hi,
i am creating a site which has a paypal integration in it....
i am bit confused in selecting a paypal product.what i want to do is, when a user clicks a pay now button, a particular amount should pass to paypal for transaction and come back to my website again.
I went through paypal documents then i got PDT(Payment Data Transfer) but here they have not shown me how to send a particular amount.
As i am new to the paypal, i am bit confused.....plz help me.
coolsatty
|
|
|
|
|
Could you not try getting in contact with paypal tech support? I'm sure they'll be able to tell you the best option.
|
|
|
|
|
Hello All,
I want to get all System IP address Which is running from a DNS Server.
Thanks
|
|
|
|
|
Please Google first before you post , there are plenty examples
IP list, Check an IP number against a list in C#[^]
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
public static string GetClientIP()<br />
{<br />
string ip;<br />
string[] temp;<br />
bool isErr = false;<br />
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"] == null)<br />
ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();<br />
else<br />
ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"].ToString();<br />
if (ip.Length > 15)<br />
isErr = true;<br />
else<br />
{<br />
temp = ip.Split('.');<br />
if (temp.Length == 4)<br />
{<br />
for (int i = 0; i < temp.Length; i++)<br />
{<br />
if (temp[i].Length > 3) isErr = true;<br />
}<br />
}<br />
else<br />
isErr = true;<br />
}<br />
if (isErr)<br />
return "1.1.1.1";<br />
else<br />
return ip;<br />
}<br />
living none stoping.
|
|
|
|
|
Hi there..
I am a new user of .net and don't know much about it.I wanna make a application when i upload a video file it should be split into chunks and get uploaded simultaneously (means all the chunks get uploaded at the same time)but don't know how to split the single file into chunks and integrate it at the receiving end is well.
I hope you will help me as soon as possible.
Thanks In Advance
Thanks & Regards
Naved Mohammad
|
|
|
|
|
Only using HTML in client side cant do this. You need flash objects for this.
HTML Input type=file can only send files up in continuous stream.
|
|
|
|
|
Hi abhishek,
Thanks for replying man.I don't have any idea about flash objects,even i never ever heared about it is well,so Will you help or guide me to acheive this.
Hope you will reply as soon as possible. Smile
Thanks & Regards
Naved Mohammad
|
|
|
|
|
hai all,
am using the following code for encryption and decryption for a password field.
But when am testing this with TamperIE for web security,there the password is showing in plian text,so any hacker can do anything,
My code is
Private Function Decrypt(ByVal myString As String) As String
cryptDES3.Key = cryptMD5Hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(Session("salt")))
cryptDES3.Mode = CipherMode.ECB
Dim desdencrypt As ICryptoTransform = cryptDES3.CreateDecryptor()
Dim buff() As Byte = Convert.FromBase64String(myString)
Decrypt = ASCIIEncoding.ASCII.GetString(desdencrypt.TransformFinalBlock(buff, 0, buff.Length))
End Function
Private Function Encrypt(ByVal myString As String) As String
cryptDES3.Key = cryptMD5Hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(session("salt")))
cryptDES3.Mode = CipherMode.ECB
Dim desdencrypt As ICryptoTransform = cryptDES3.CreateEncryptor()
Dim MyASCIIEncoding = New ASCIIEncoding
Dim buff() As Byte = ASCIIEncoding.ASCII.GetBytes(myString)
Encrypt = Convert.ToBase64String(desdencrypt.TransformFinalBlock(buff, 0, buff.Length))
End Function
The above code is am calling on pageload like
txt_password.text=encrypt(txt_password.text)
str=decrypt(txt_password.text)
It is working perfectly.
But if i tested with TamperIE it is showing plian text.Then how to do this?What i have to use,so that it should not show in plain text for the end user???
Sorry if i disturb u,please let me now the answer
kissy
|
|
|
|
|
Kissy16 wrote: am using the following code for encryption and decryption for a password field.
Password fields should be stored as a one-way salted hash value (e.g. SHA256). That way you (or a hacker) can never get them back. When you want to check that a password matches then you create a salted hash of what the user typed and compare the two hashed values.
Kissy16 wrote: But if i tested with TamperIE it is showing plian text
At what point is it showing plain text. What the user types in will be in plain text until you encrypt it.
|
|
|
|
|
ya.
Actually i am using plain text passwords in the back end.
when i use salted hash on the new password field,then while changing password,it will become the hashed password getting updated which i want to store as plain text.
So this is my question ki how to do that?storing the changed password as plain text and not the hashed one.
kissy
|
|
|
|
|
|
Actually, I read some advice recently that suggested that it is better to move authentication over to a dedicated service that can implement it better than you can. I've since started using OpenID as the authentication mechanism for my websites so I never have to store passwords again.
You might want to look into OpenID frameworks for .NET.
|
|
|
|