使用DataBinder和用户定义的方法绑定网格 [英] Binding grid using DataBinder with user defined method

查看:61
本文介绍了使用DataBinder和用户定义的方法绑定网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的活页夹功能

< asp:label id ="lbl" text =<%#DataBinder.Eval(Container.DataItem," runat ="server" xmlns:asp =#unknown"> ;;

我在代码背后有一个这样的方法

公共字符串GetName(字符串ID)
{
if(id =="1")
返回一个";
其他
返回其他";
}

根据Eval方法中的id,我想从方法GetName()绑定相应的字符串值.

如何在Label内调用方法GetName(),该方法接受"Id"作为参数?

I have Binder function like this

<asp:label id="lbl" text="<%#DataBinder.Eval(Container.DataItem, " runat="server" xmlns:asp="#unknown">;

I have one method in code behind like this

public string GetName(string id)
{
if(id == "1")
return "One";
else
return "Something else";
}

Depending on the id in Eval method I want to bind the corresponding string values from the method GetName().

How can I call the method GetName(), which accepts "Id" as parameter, inside the Label ?

推荐答案

尝试一下.
Try this.

<asp:Label id="lblTest" runat="server" Text=''<%#GetName(Eval("Id").ToString()) %>''>/xml>


这篇关于使用DataBinder和用户定义的方法绑定网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆