我正在动态填充保存在我的数据库中的文本框的 ID。从确定搜索参数的数据集中提取值时,我将其设置为字符串。
我现在想将字符串参数用作使用客户端 ID 的 Attributes.Add 方法的动态 ID。我需要的最终结果是使用 onfocus 事件为 ASP:Textbox 填充日期选择器。
示例如下:
//setting the value of the item from the dataset
string textCode = ds.Tables["CONTROLS"].Rows[1]["TEXTCODE"].ToString();
//inserting the value for use with ClientID
textCode.Attributes.Add("onfocus", "datepicker('" + textCode.ClientID + "');");
我收到以下错误:“'string' does not contain a definition for 'ClientID' accept the first argument of 'string' can be found(您是否缺少 using 指令或程序集引用”)”。
当我尝试将另一个变量转换或设置为 ClientID 可用的 HtmlControl 时:
HtmlControl txtCode = textCode;
我收到以下错误:“无法将 'string' 隐式转换为 'System.Web.UI.HtmlControls.HtmlControl'”
如何转换为使用此动态 ID?
预先感谢您的建议。