asp.net DataGrid控制項中彈出詳細資料視窗

來源:互聯網
上載者:User

在DataGrid控制項中添加超連結如下步驟:
(1) 在"設計"視圖中,選擇DataGrid控制項,然後單擊"屬性"視窗底部的"屬性產生器"連結。
(2) 在"DataGrid屬性"對話方塊中單擊"列"選項卡。
(3) 在"可用列"選項框中,選擇"超級連結列"並單擊"添加"按鈕。如進行添加超級連結列的設定。

(4) 若要將資料欄位用作目標頁URL的源,請從"URL欄位"文字框中填寫該欄位名。在這種情況上,可以使用
"URL 格式字串"選項框為該超級連結文本指定格式設定運算式。
"URL格式字元口串"目標URL為:javascript:varwin=window.open('detail.aspx?ID={0}',null,'width=300,height=200');window.Close();
分別建立兩個頁面,一個用來添加DataGrid控制項並設定超級連結列,而後者是被彈出的頁面,後者頁面的頁面代碼好下:
<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>
後者頁面的後台代碼:
頁面的載入事件
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置使用者代碼以初始化頁面
if(!IsPostBack)
{
this.DataGridBind();
}
}
資料繫結事件
private void DataGridBind()
{
string EmpID = Request["ID"].ToString();
//調用Web.config資料庫連接字元
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();
}
}
編譯運行點擊設定超級連結列就可以彈出相應行的詳細資料
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.