2011-12-20 54 views
0

我有我的數據源中的字段,我想結合並顯示在一個標籤字段中。我添加了一個過程來捕獲數據綁定操作,但我不知道如何從數據源中獲取數據。我在FormView上顯示這些信息是非常重要的。我可以在c#中獲得示例嗎?FormView數據綁定

例如 -

protected void DisplayPayOut(object sender, EventArgs e) 
{ 
    Label Payout = FormView1.FindControl("PayoutLabel") as Label; 
    Payout.Text = datasource.field1 + datasource.field2; 
} 
+0

確實你當前的代碼產生任何結果錯誤的等..? – MethodMan 2011-12-20 21:16:35

+0

這只是示例代碼..實際的數據源是SqlDataSource,查詢中的兩個字段是「wire」和「ach」。我想要的結果是有標籤字段=線ach – Craig 2011-12-20 21:21:42

+0

好吧,讓我改述..你有代碼,可以讓你執行查詢對數據源..從你有什麼爲什麼不抨擊var splitText = datasource.field1 .ToString()+「」+ datasource2.ToString();並查看splitText字符串變量的結果是什麼..除此之外,很難真正知道你需要什麼,而不會看到你已經嘗試過的一些實際的書面代碼。 – MethodMan 2011-12-20 21:29:12

回答

2

我不能完全肯定,但好像你正在尋找的東西像下面這樣:

protected void DisplayPayOut(object sender, EventArgs e) 
{ 
    Label Payout = FormView1.FindControl("PayoutLabel") as Label; 
    object dataItem = DataBinder.GetDataItem(FormView1); 
    Payout.Text = DataBinder.Eval(dataItem, "field1NameHere").ToString() + DataBinder.Eval(dataItem, "field2Namehere").ToString(); 
} 
相關問題