如何将数据绑定到DetailsView中的查找控件中? [英] how to bind the data into find controls in detailsview?

查看:58
本文介绍了如何将数据绑定到DetailsView中的查找控件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标签displayNameLabel = DetailsView1.FindControl("lblDisplayName")作为标签;
如果(displayNameLabel == null)
{
投掷;
}
字符串testResult = ds.Tables [0] .Rows [0] [0] .ToString();

无法将值从testResult存储到displayNameLable ...
请解决此问题....

解决方案

两个问题之一,要么Label find控件未提取结果,要么Table实际上未提取结果.弄清楚这一点的简单方法是将表作为字符串,将标签作为标签.

标签displayNameLabel = DetailsView1.FindControl(" )作为标签;
如果(displayNameLabel == )
{
     投掷;
}
字符串 testResult = ds.Tables [ 0 ].Rows [ 0 ] [ 0 ].ToString(); 



然后,这只是纠正单个错误的问题.但是,这是一个非常普遍要求的问题,而控件的查找可能很棘手.它必须是模板,并且当然必须是标签,并且如果在DetailsView中,则可以轻松地从设计人员设置绑定,而无需在背后的代码中手动进行... Google DetailsView绑定以获取更多帮助或查看此示例在DetailsView控件中使用TemplateFields . /blockquote>

Label displayNameLabel = DetailsView1.FindControl("lblDisplayName") as Label;
if (displayNameLabel == null)
{
throw;
}
string testResult = ds.Tables[0].Rows[0][0].ToString();

it is not possible to store the value from testResult to displayNameLable...
please solve this problem....

解决方案

One of two problems, either the Label findcontrol is not pulling a result or the Table is in fact not pulling a result. Easy way to figure that out is to grab the table as a string and the label as a label.

Label displayNameLabel = DetailsView1.FindControl("lblDisplayName") as Label;
if (displayNameLabel == null)
{
     throw;
}
string testResult = ds.Tables[0].Rows[0][0].ToString();



Then it''s just a matter of correcting the individual error. This is a very widely requested issue though and the finding of controls can be tricky. It must be a template, and it must of course be a label, and if it''s in DetailsView you can easily set up binding from the designer instead of manually in code behind... Google DetailsView binding for more help or look at this example Using TemplateFields in the DetailsView Control.


这篇关于如何将数据绑定到DetailsView中的查找控件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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