![](/img/trans.png)
[英]Writing a SQLdatasource in code behind in C# to use a code behind value
[英]Accessing data from my SqlDataSource in the code behind C# .net
我有一個聯系頁面,其中有一個人的數據主義者,如果你點擊其中一個,你會得到一個我想發送給該特定人的聯系表。
我使用sqldatasource dscontactemail獲取有關該人員的信息以放置在聯系表單上,但是當我准備發送該郵件時,如何從后面的代碼中獲取dscontactemail的信息?
我在頁面上放了一個formview來顯示這個人的圖片,我可以通過<%#Eval(“email”)從dscontactemail獲得我想要的任何東西,但是如何從后面的代碼中獲得呢?
我嘗試了一個隱藏的字段,但它沒有用。
從后面的代碼訪問頁面上的SqlDataSource的任何其他方法?
首先,你真的應該從某個時候開始使用SqlDataSource到SqlClient命名空間中可用的類,所以請記住這一點。
以下是執行此操作的代碼:
DataView dview = CType(yourSqlDataSource.Select(DataSourceSelectArguments.Empty), DataView);
string str = "";
foreach(DataRow drow dview.Table.Rows)
{
str += drow("yourcol1").ToString() + "<br />";
}
以下綽綽有余:
dv = yourSqlDataSource.Select(DataSourceSelectArguments.Empty) as DataView;
並分別詢問DataView。
如果intellisense沒有拾取yourSqlDataSource,那么只需通過具有數據源的控件的FindControl()綁定它:
SqlDataSource sdsPreStartDates = (SqlDataSource)DetailsView1.FindControl("sdsPreStartDates");
if (sdsPreStartDates != null)
{
DataView dv1 = (DataView)sdsPreStartDates.Select(DataSourceSelectArguments.Empty);
..
.. etc
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.