Connecting Sqlserver2008 Code Instances

Source: Internet
Author: User
Tags httpcontext


{
public partial class _default:system.web.ui.page
{


Private SqlCommand cmd = new SqlCommand ();


protected void Page_Load (object sender, EventArgs e)
{

HttpContext context1 = HttpContext.Current;
HttpContext context2 = System.Runtime.Remoting.Messaging.CallContext.HostContext as HttpContext;
BOOL IsEqual = object. ReferenceEquals (Context1, CONTEXT2);
Response.Write ("Two object values" + isequal);


Add Row data
Try
{
DataTable dt = Selectzhibotop ("z_flag=1 ORDER BY id DESC");
if (dt. Rows.Count > 0)
{
Gridview1.datasource = DT;
Gridview1.databind ();
}
}
Catch
{
Response.Write ("Bind database Error! ");
}

}

protected void GridView1_SelectedIndexChanged (object sender, EventArgs e)
{

}

protected void Gridview1_rowcommand (object sender, Gridviewcommandeventargs e)
{
GridView _gridview = (gridview) sender;

Get the selected index and the command name

int _selectedindex = Int. Parse (E.commandargument.tostring ());
string _commandname = E.commandname;

Switch (_commandname)
{
Case ("Singleclick"):
_gridview.selectedindex = _selectedindex;
This. Message.Text + = "Single clicked GridView Row at index"
+ _selectedindex.tostring () + "<br/>";
Break
Case ("DoubleClick"):
This. Message.Text + = "Double clicked GridView Row at index"
+ _selectedindex.tostring () + "<br/>";
Break
}
}

protected void GridView1_RowDataBound (object sender, GridViewRowEventArgs e)
{
if (E.row.rowtype = = Datacontrolrowtype.datarow)
{
Get the LinkButton control in the first cell

LinkButton _singleclickbutton = (LinkButton) e.row.cells[0]. Controls[0];
Get the JavaScript which is assigned to this LinkButton

String _jssingle =
Clientscript.getpostbackclienthyperlink (_singleclickbutton, "");
To prevent the first click from posting back immediately

(therefore giving the user a chance to double click)

Pause the postbackfor milliseconds by

Wrapping the postback command in a setTimeout

_jssingle = _jssingle.insert (One, "SetTimeout (\" ");
_jssingle + = "\", 300) ";
Add this javascript to the onclick Attribute of the row

e.row.attributes["onclick"] = _jssingle;

Get the LinkButton control in the second cell

LinkButton _doubleclickbutton = (LinkButton) e.row.cells[1]. Controls[0];
Get the JavaScript which is assigned to this LinkButton

String _jsdouble =
Clientscript.getpostbackclienthyperlink (_doubleclickbutton, "");
Add this javascript to the ondblclick Attribute of the row

e.row.attributes["ondblclick"] = _jsdouble;
}
}


Check all live
Public DataTable selectzhibotop (String sql)
{


String SQL1 = "SELECT top 2 id,z_title from R_zhibo";
if (SQL. Trim ()! = "")
{
SQL1 + = "where" + SQL;
}
DataTable dt = ExecuteDataset (SQL1); Ds. Tables[0];
return DT;
}


Public DataTable ExecuteDataset (String sql)
{
DataSet ds = null;
SqlDataAdapter da = null;
da = new SqlDataAdapter ();
ds = new DataSet ();
DataTable dt = null;
DT = new DataTable ();

SqlCommand cmd = new SqlCommand ();
Try
{
SqlConnection conn = new SqlConnection ();
Conn. ConnectionString = "Server=yaoxiaozhong;initial catalog=lzh_jy_db;uid=sa;pwd=kd789123_qwe; Max Pool size=150; Connect timeout=500; ";
Cmd. Connection = conn;
Cmd.commandtext = SQL;
Cmd.commandtype = CommandType.Text;
Cmd.commandtype = Baseparser;

Da. SelectCommand = cmd;
Da. Fill (DT);

}

Catch
{throw;}
return DT;
}


protected void Gridview1_prerender (object sender, EventArgs e)
{
foreach (GridViewRow R in Gridview1.rows)
{
if (R.rowtype = = Datacontrolrowtype.datarow)
{
Page.ClientScript.RegisterForEventValidation
(R.uniqueid + "$ctl 00");
Page.ClientScript.RegisterForEventValidation
(R.uniqueid + "$ctl 01");
}
}

Base. Render (writer);
}

}
}

Connecting Sqlserver2008 Code Instances

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.