开发者

How can I inline database access code?

I have an aspx page, from where I want to give if condition. I have a parameterized function in app_code, which returns a value. I want to check values for blank, if the value is blank, it should execute the else block. This function I want to call under gridview ItemTemplate. and the parameter is the database field "ID" value.

In other words, here is what I want to do..

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

Here is what I am doing.

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

Can anyone suggest how to call my database field 开发者_如何转开发in this way?


I think that this is what you ask
You call the function this way

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

and the code behind.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜