如何在用作eval的公共字符串上传递空值 [英] How to pass null values on public string that is being used as eval

查看:117
本文介绍了如何在用作eval的公共字符串上传递空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我单击按钮passnullvalue_OnClick时,我想在我的公共字符串ProcessMyVideo(字符串myValue)上传递null值。我正在使用ProcessMyVideo在字符串上添加videocontrol,文件的路径是我从文字中获取file_location。没有错误但是在我的公共字符串ProcessMyVideo上传递null值不起作用意味着每次我单击我的passnullvalue_OnClick而不是从ProcessMyVideo使myValue为null时它仍然从file_location获取值。请告诉我该怎么办。告诉我是否有可能。



我尝试过:



在我的服务器上:



I wanted to pass null value on my public string ProcessMyVideo(string myValue) whenever my button passnullvalue_OnClick is clicked. I'm using ProcessMyVideo to add videocontrol on string with the path of file I'm getting file_location from my literal. There's no error but passing null value on my public string ProcessMyVideo is not working meaning every time I click my passnullvalue_OnClick instead of making the myValue null from ProcessMyVideo it still getting the value from file_location. Please let me know what should I do. Just tell me if it's possible.

What I have tried:

On my server:

public string ProcessMyVideo(string myValue)
{
    if(myValue == null)
    {
    string locpath = "<video class=video_class Controls><Source type=video/mp4>
    </video>";
    return locpath;
    }
    if (myValue != null)
    {
    string locpath = "<video class=video_class Controls><Source src=" +
    myValue + " type=video/mp4></video>";
    return locpath;
    }
    return myValue;
}





我的按钮:





On My Button:

protected void passnullvalue_OnClick(object sender, EventArgs e)
    {
        string nullvalue = null;
        ProcessMyVideo(nullvalue);
    }





我的客户:



这个文字放在我的ListView的ItemTemplate上





On my client:

this literal is placed on ItemTemplate of my ListView

<asp:Literal ID="videoshow" runat="server"Text='<%#ProcessMyVideo(Eval("file_location").ToString()) %>' ></asp:Literal>

推荐答案

试试这个:

Try this:
public string ProcessMyVideo(string myValue)
{
    string src = (string.IsNullOrEmpty(myValue))?"":string.Format("src='{0}' ",myValue);
    return string.Format("<video class=video_class Controls><Source {0}type=video/mp4></video>", src);
}


这篇关于如何在用作eval的公共字符串上传递空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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