
在DataGrid控件中添加超鏈接如下步驟:
(1) 在"設(shè)計(jì)"視圖中,選擇DataGrid控件,然后單擊"屬性"窗口底部的"屬性生成器"鏈接。
(2) 在"DataGrid屬性"對(duì)話框中單擊"列"選項(xiàng)卡。
(3) 在"可用列"選項(xiàng)框中,選擇"超級(jí)鏈接列"并單擊"添加"按鈕。如下圖進(jìn)行添加超級(jí)鏈接列的設(shè)置。

(4) 若要將數(shù)據(jù)字段用作目標(biāo)頁(yè)URL的源,請(qǐng)從"URL字段"文本框中填寫(xiě)該字段名。在這種情況上,可以使用
"URL 格式字符串"選項(xiàng)框?yàn)樵摮?jí)鏈接文本指定格式設(shè)置表達(dá)式。
"URL格式字符口串"目標(biāo)URL為:javascript:varwin=window.open('detail.aspx?ID={0}',null,'width=300,height=200');window.Close();
分別創(chuàng)建兩個(gè)頁(yè)面,一個(gè)用來(lái)添加DataGrid控件并設(shè)置超級(jí)鏈接列,而后者是被彈出的頁(yè)面,后者頁(yè)面的頁(yè)面代碼好下:
<form id="Form1" method="post" runat="server">
<FONT face="宋體">
<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 32px" cellSpacing="0"
cellPadding="1" width="300" border="0">
<TR>
<TD style="WIDTH: 65px">姓名:</TD>
<TD>
<asp:TextBox id="tbxName" runat="server" Width="184px"></asp:TextBox></TD>
</TR>
<TR>
<TD style="WIDTH: 65px">生日:</TD>
<TD>
<asp:TextBox id="tbxBri" runat="server" Width="184px"></asp:TextBox></TD>
</TR>
<TR>
<TD style="WIDTH: 65px">地址:</TD>
<TD>
<asp:TextBox id="tbxAdd" runat="server" Width="184px"></asp:TextBox></TD>
</TR>
<TR>
<TD style="WIDTH: 65px">城市:</TD>
<TD>
<asp:TextBox id="tbxCity" runat="server" Width="184px"></asp:TextBox></TD>
</TR>
</TABLE>
</FONT>
</form>
后者頁(yè)面的后臺(tái)代碼:
頁(yè)面的載入事件
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁(yè)面
if(!IsPostBack)
{
this.DataGridBind();
}
}
數(shù)據(jù)綁定事件
private void DataGridBind()
{
string EmpID = Request["ID"].ToString();
//調(diào)用Web.config數(shù)據(jù)庫(kù)連接字符
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionSqlServer"].ToString());
SqlCommand cmd = new SqlCommand("select LastName,FirstName,BirthDate,Address,City from Employees where EmployeeID="+EmpID.ToString(),conn);
conn.Open();
try
{
SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
{
this.tbxName.Text = dr["LastName"].ToString();
this.tbxBri.Text = Convert.ToDateTime(dr["BirthDate"]).ToLongDateString();
this.tbxAdd.Text = dr["Address"].ToString();
this.tbxCity.Text = dr["City"].ToString();
}
}
catch(Exception e)
{
Response.Write(e.ToString());
}
finally
{
conn.Close();
}
}
編譯運(yùn)行點(diǎn)擊設(shè)置超級(jí)鏈接列就可以彈出相應(yīng)行的詳細(xì)信息
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com