System.Web.HttpContext.Current.Session["name"] |
Application
System.Web.HttpContext.Current.Application["name"] |
QueryString
System.Web.HttpContext.Current.Request.QueryString["name"] |
System.Web.HttpContext.Current.Session["name"] |
System.Web.HttpContext.Current.Application["name"] |
System.Web.HttpContext.Current.Request.QueryString["name"] |
DateTime d = DateTime.Now; Response.Write("<br />today: " + d + "<br />"); //today: 11/18/2009 6:03:02 PM Response.Write("<br />today: " + d.ToShortTimeString() + "<br />"); //today: 6:03 PM Response.Write("<br />day: " + d.ToString("d dd ddd dddd") + "<br />"); //day: 18 18 Wed Wednesday Response.Write("<br />month: " + d.ToString("M MM MMM MMMM") + "<br />"); //month: 11 11 Nov November Response.Write("<br />year: " + d.ToString("y yy yyy yyyy") + "<br />"); //year: 9 09 2009 2009 Response.Write("<br />hour: " + d.ToString("h hh H HH") + "<br />"); //hour: 6 06 18 18 Response.Write("<br />minute: " + d.ToString("m mm") + "<br />"); //minute: 3 03 Response.Write("<br />second: " + d.ToString("s ss") + "<br />"); //second: 2 02 Response.Write("<br />AM/PM: " + d.ToString("t tt") + "<br />"); //AM/PM: P PM |
<asp:ItemTemplate> <asp:asp:ImageButton ID="imgUpdate" runat="server" CommandName="Update1" CommandArgument='<%# Eval("id") %>' ImageUrl="~/icons/Update001 (2).gif" /> <asp:/ItemTemplate> |
Dim selectedRow As GridViewRow = DirectCast(DirectCast(e.CommandSource, LinkButton).NamingContainer, GridViewRow) Dim intRowIndex As Integer = Convert.ToInt32(selectedRow.RowIndex) GridView.Rows(intRowIndex).BackColor = System.Drawing.Color.Blue |
GridViewRow selectedRow = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer; int intRowIndex = Convert.ToInt32(selectedRow.RowIndex); GridView.Rows[intRowIndex].BackColor = System.Drawing.Color.Blue; |
Dim selectedRow As GridViewRow = GridView.Rows(Convert.ToInt32(e.CommandArgument)) selectedRow.BackColor = System.Drawing.Color.Blue |
GridViewRow selectedRow = GridView.Rows[Convert.ToInt32(e.CommandArgument)]; selectedRow.BackColor = System.Drawing.Color.Blue; |
=(DATE(YEAR(NOW()), MONTH(NOW()), DAY(NOW())) + TIME(HOUR(NOW()),MINUTE(NOW()),SECOND(NOW()))) |
=NETWORKDAYS(startdate, enddate) |
protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("page2.aspx?userid=" + TextBox1.Text + "&username=" + Textbox2.Text); } |
string strUserID = Request.QueryString["userid"]; string strUserName = Request.QueryString["username"]; |
protected void Button1_Click(object sender, EventArgs e) { Session["userid"] = TextBox1.Text; Session["username"] = TextBox2.Text; Response.Redirect("page2.aspx"); } |
string strUserID = Session["userid"].ToString(); string strUserName = Session["username"].ToString(); |
protected void Button1_Click(object sender, EventArgs e) { Server.Transfer("page2.aspx", true); } |
string strUserID = Request.Form["TextBox1"]; string strUserName = Request.Form["TextBox2"]; |
protected void Button1_Click(object sender, EventArgs e) { HttpCookie cookie = new HttpCookie("UserID"); cookie.Value = TextBox1.Text; cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); HttpCookie cookie = new HttpCookie("UserName"); cookie.Value = TextBox2.Text; cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); Response.Redirect("WebForm2.aspx"); } |
string strUserID = Request.Cookies["UserID"].Value; string strUserName = Request.Cookies["UserName"].Value; |
protected void Button1_Click(object sender, EventArgs e){ Server.Transfer("page2.aspx"); } |
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { TextBox txt1 = (TextBox)Page.PreviousPage.FindControl("TextBox1"); TextBox txt2 = (TextBox)Page.PreviousPage.FindControl("TextBox2"); string strUserID = txt1.Text; string strUserName = txt2.Text; } } |
function validnumber(ev) { ev.returnValue = (ev.keyCode>=48 && ev.keyCode<=57); } <asp:TextBox ID="txtInt" runat="server" onkeypress="validnumber(event)" /> |
function validfloat(txt, ev) { ev.returnValue = ((ev.keyCode>=48 && ev.keyCode<=57) ev.keyCode==46 && txt.value.indexOf('.') == -1); } <asp:TextBox ID="txtFloat" runat="server" onkeypress="validfloat(this, event)" />> |
<asp:TextBox ID="txtAjaxInt" runat="server" /> <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" TargetControlID="txtAjaxInt" FilterType="Numbers" runat="server" /> |
<asp:TextBox ID="txtAjaxFloat" runat="server" /> <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" TargetControlID="txtAjaxFloat" FilterType="Custom, numbers" ValidChars="." runat="server" /> <asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server" ControlToValidate="txtAjaxFloat" ErrorMessage="Enter a valid float" ValidationExpression="\d+\.\d{2}" /> <asp:button id="btn1" runat="Server" text="test float" /> |
UserID | UserName | Country |
1 | James | USA |
2 | Amy | Canada |
3 | Charles | Singapore |
DECLARE @string varchar(100) SET @string = '1,James,USA;2,Amy,Canada;3,Charles,Singapore;' DECLARE @delimiter1 CHAR(1) DECLARE @delimiter2 CHAR(1) SET @delimiter1 = ';' SET @delimiter2 = ',' DECLARE @pos as int SET @pos = charindex(@delimiter1, @string) DECLARE @temp AS NVARCHAR(1000) DECLARE @country NVARCHAR(100) DECLARE @username NVARCHAR(100) DECLARE @userid INT DECLARE @tbl_user TABLE (userid int, username varchar(50), country varchar(50)) WHILE(@pos > 0) BEGIN SET @temp = SUBSTRING(@string, 0, @pos) SET @userid = SUBSTRING(@temp, 0, CHARINDEX(@delimiter2, @temp)) SET @username = SUBSTRING(@temp, CHARINDEX(@delimiter2, @temp) + 1, CHARINDEX(@delimiter2, @temp, CHARINDEX(@delimiter2, @temp) + 1) - CHARINDEX(@delimiter2, @temp) - 1) SET @country = SUBSTRING(@temp, CHARINDEX(@delimiter2, @temp, CHARINDEX(@delimiter2, @temp) + 1) + 1, @pos - CHARINDEX(@delimiter2, @temp, CHARINDEX(@delimiter2, @temp) + 1)) INSERT INTO @tbl_user (userid, username, country) VALUES (@userid, @username, @country) SET @string = SUBSTRING(@string, charindex(@Delimiter1,@String) + 1, LEN(@string) - charindex(@Delimiter1,@String)) SET @pos = charindex(@Delimiter1,@string) END SELECT * FROM @tbl_user |
CREATE TABLE #tbl_user(userid int,username varchar(50)) INSERT INTO #tbl_user (userid, username) SELECT 1, 'user name 1' UNION ALL SELECT 2, 'user name 2' UNION ALLS SELECT 3, 'user name 3' SELECT * FROM #tbl_user DROP TABLE #tbl_user |
DECLARE @tbl_user TABLE ( userid int, username varchar(50)) INSERT INTO @tbl_user (userid, username) SELECT 1, 'user name 1' UNION ALL SELECT 2, 'user name 2' UNION ALL SELECT 3, 'user name 3' SELECT * FROM @tbl_user |
CREATE TABLE tbl_user ( userid int, username varchar(50)) INSERT INTO tbl_user (userid, username) SELECT 1, 'user name 1' UNION ALL SELECT 2, 'user name 2' UNION ALL SELECT 3, 'user name 3' SELECT * FROM tbl_user --DROP TABLE tbl_user |
Here im going to demonstrate how can you concate all the values in multiple rows into a single value:
Data
TABLE: @tbl_user_request
Raw data
userid request_id
1 'A000001'
1 'A000002'
2 'A000003'
3 'A000004'
4 'A000005'
5 'A000006'
5 'A000007'
Expected result
userid request_id
1 A000001,A000002
2 A000003
3 A000004
4 A000005
5 A000006,A000007
DECLARE @tbl_user_request TABLE (userid int, request_id varchar(50)) INSERT INTO @tbl_user_request SELECT 1, 'A000001' UNION ALL SELECT 1, 'A000002' UNION ALL SELECT 2, 'A000003' UNION ALL SELECT 3, 'A000004' UNION ALL SELECT 4, 'A000005' UNION ALL SELECT 5, 'A000006' UNION ALL SELECT 5, 'A000007' SELECT a.userid, request_id=substring((SELECT ( ', ' + request_id) FROM @tbl_user_request b WHERE a.userid=b.userid ORDER BY userid FOR XML PATH('')), 3, 1000)FROM @tbl_user_request a GROUP BY userid |
note
There is a subquery in the SQL which joining the same table as the main query. The purpose of this subquery is to select all the "requet_id" pertaining to the same userid in the "tbl_user" table and concatenate them into a single "concatename" variable by using the FOR XML PATH
For more example you can refer here:
http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=createacommadelimitedlist