2011-04-28 31 views
0

我有一個aspx頁面,從那裏我想給如果條件。我在app_code中有一個參數化函數,它返回一個值。我想檢查空白值,如果值爲空白,它應該執行else塊。這個函數我想在gridview ItemTemplate下調用。並且該參數是數據庫字段「ID」值。如何嵌入數據庫訪問代碼?

換句話說,這裏就是我想要做的..

if functionName(parameter is databaseField Value) Then 
    functionName(parameter is databaseField Value) 
End If 

下面是我在做什麼。

<% If customTransactions.GetAuthorToBlogEntry(
    CType(DataBinder.Eval(Container.DataItem,"EntryID"), Integer)) <> "" %> 
    by 
<% End If %> 

任何人都可以建議如何以這種方式調用我的數據庫字段?

+0

你的問題有點不清楚。你能提供更多信息嗎?也許顯示一些你已經嘗試過的代碼? – 2011-04-28 18:26:38

+0

@Alison:我想在aspx頁面中使用內聯代碼,想要調用參數化函數,其參數值將是數據庫字段。我想在gridview的ItemTemplate下調用這個函數,上面我指定了我所嘗試的。 – Abbas 2011-04-28 19:07:27

回答

0

我認爲這是你問
調用該函數這種方式

<asp:TemplateField HeaderText="Header Title" > 
    <ItemTemplate ><%#GetYourData(Container.DataItem)%></ItemTemplate> 
</asp:TemplateField>     

和後面的代碼。

protected string GetYourData(object oItem) 
{ 
    // here is the way you get the data on code behind 
    return DataBinder.Eval(oItem, "EntryID").ToString(); 
} 
相關問題