如何在FormView中从隐藏代码给隐藏文件赋值 [英] How to give value to hiddenfiled from codebehind in formview

查看:72
本文介绍了如何在FormView中从隐藏代码给隐藏文件赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好先生,

我正在尝试从代码隐藏中为hiddenfield赋予价值.这是我的代码:

hello sir,

i am trying to give value to hiddenfield from codebehind. here is my code:

HiddenField hf = (HiddenField)FormView1.FindControl("hdnvideo");
               hf.Value = "123";



我需要将"123"传递给hdnvideo类型hiddenfield.
当前会将值传递给hf类型hiddenfield.

请帮助我:

thanx



I need to pass the "123" to hdnvideo type hiddenfield.
it''s currently passing the value to hf type hiddenfield.

please help me on this:

thanx

推荐答案

我有几个问题要问你

1.您的表格是否包含在母版页中?
2.如果是这样,我希望ForView在ContentPlaceHolder上.对吗?

如果是,请继续阅读.

当控件驻留在内容占位符中时,asp.net会自动将ID附加为ctl00.尽管ID为hdnVideo,但运行时它可能会附加ct100并形成ID.我建议您运行页面并从浏览器运行,请单击查看源代码"并查找是否使用ctl00生成了id.我不确定这是否是实际问题.仅是我的建议.
I have a few questions for you

1.Is your form included within master page?
2.If so,I hope ForView is on a ContentPlaceHolder.Is that correct?

If the answer is yes,read further.

When controls reside in a content place holder asp.net automatically appends the IDs with ctl00.Though the id is hdnVideo,run time it might be getting appended with ct100 & forming a id.I would suggest,you run the page & from the browser,click on View Source & find out if an id is generated with ctl00.I am not sure whether this is the actual problem.Just a suggestion from my side.


aspx页面中的代码:

Code in aspx page:

<input type="hidden" name="hdnVideo" value="" ID="someID" runat="server">



背后的代码:



Code behind:

// Simply acccess the hidden field by its name. It is automatically
// declared because of runat="server"
hdnVideo.Value = "123";



最好的问候,
曼弗雷德(Manfred)



Best Regards,
Manfred


我不知道为什么从FormView1中找到.

尝试从Page,Like
找到它
I don''t have any clue why you are finding from FormView1.

Try to find it from Page, Like

HiddenField hdn = (HiddenField)Page.FindControls("hdnVideo");
hdn.Value = "123";



并且确保HiddenField被标记为Runat="Server"



And Make sure that HiddenField is marked Runat="Server"


这篇关于如何在FormView中从隐藏代码给隐藏文件赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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