简体   繁体   English

从文件背后的代码中使用C#获取自定义属性的值

[英]Get value of custom attribute with c# from the code behind file

I've the code below where I dynamically give the div a value for the attribute "data-order". 我在下面的代码中为div动态分配了“数据顺序”属性的值。 I'd like be able to grab this value with c# from the code behind file, but I unfortunately cant figure out how to do it. 我希望能够使用c#从文件背后的代码中获取此值,但是很遗憾,我无法弄清楚该怎么做。

<asp:ListView ID="display_backlog" runat="server" DataSourceID="get_backlog" DataKeyNames="story_id">
    <EmptyDataTemplate>
        <p>There is no stories in the product backlog for this project.</p>
    </EmptyDataTemplate>
    <ItemTemplate>
        <div class="row" CssClass="sortable-item" runat="server" data-order="" data-id='<%# Eval("story_id") %>'>
                <div class="col-12">
                    <div class="panel">
                        <p><asp:Label Text='<%# Eval("story_title") %>' runat="server" ID="story_titleLabel" /></p> 
                    </div>
                </div>
            </div>
    </ItemTemplate>
    <LayoutTemplate>
        <div runat="server" id="itemPlaceholderContainer" style=""><span runat="server" id="itemPlaceholder" /></div>
        <div style="">
        </div>
    </LayoutTemplate>
</asp:ListView>

Any help would be appreciated. 任何帮助,将不胜感激。

One possibility is to add a hidden input server control to the page and to set the value of that hidden input dynamically when you set the value of the "data-order" attribute. 一种可能性是在页面上添加隐藏的输入服务器控件,并在设置“数据顺序”属性的值时动态设置该隐藏的输入的值。 You can then get the value of the hidden input easily from the code behind (because it's a server control) whenever you submit the form, as long as the hidden server control is in the form. 然后,只要隐藏的服务器控件在表单中,就可以在提交表单时轻松地从背后的代码(因为它是服务器控件)中获取隐藏的输入的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM