I have some DropDownLists
and some TextBoxes
on a page. Normally I use this to clear and add value to the items:
我有一些下拉列表和一些文本框在页面上。通常我用它来清除和增加项目的价值:
Clear control:
明确的控制:
txtEventNote.Text = String.Empty
ddlHours.SelectedIndex = 0
Add value:
添加值:
ddlHours.SelectedValue = dtEvents.Rows(0)("EventDate")
txtEventTitle.Text = dtEvents.Rows(0)("EventHome").ToString()
But if I do this for items thats inside an ASP:LoginView
I get an error because the ID's cant be found.
但是,如果我对ASP:LoginView中的项这样做,我就会得到一个错误,因为找不到ID。
So my question is:
我的问题是:
-
How do I clear the
ddlSize
DropDownList
ID and how do i addString.Empty
totxtEventName.Text
that's inside theLoginView
which has an ID of "loginview2"?如何清除ddlSize下拉列表ID以及如何添加字符串。空txtEventName。在LoginView中具有“loginview2”ID的文本?
-
And how do I add a value to a
TextBox
andDropDownList
inside anLoginView
called "loginview2" where I have aTextBox
with the ID textEventName.Text and theDropDownList
have ID ddlSize.我如何在一个名为“loginview2”的LoginView中添加一个值到一个文本框和下拉列表,其中我有一个文本框,其中有一个ID textEventName。文本和下拉列表具有ID ddlSize。
If I delete the LoginView
it's easy for me to do, but when I add the LoginView
the ID's can't be found.
如果我删除LoginView,这对我来说很容易,但是当我添加LoginView时,就找不到ID。
1 个解决方案
#1
1
The LoginView
control is a container control. It can hold other ASP.NET WebForm controls. To get a reference to the controls contained within the LoginView
control use the FindContol
method of the LoginView
control.
LoginView控件是一个容器控件。它可以容纳其他ASP。净WebForm控制。要获取对LoginView控件中包含的控件的引用,请使用LoginView控件的FindContol方法。
TextBox tb = lcLoginView.FindControl("txtEventNote") as TextBox
if (tb != null)
{
tb.Text = "My New Value For This TextBox control";
}
Do the same for your DropDownList
.
对下拉列表也一样。
I found In Search Of ASP.Net Controls to be helpful for more about finding ASP.NET controls in other ASP.NET controls.
我在寻找ASP。Net控件有助于更多地找到ASP。NET控件在其他ASP中。网络控制。
#1
1
The LoginView
control is a container control. It can hold other ASP.NET WebForm controls. To get a reference to the controls contained within the LoginView
control use the FindContol
method of the LoginView
control.
LoginView控件是一个容器控件。它可以容纳其他ASP。净WebForm控制。要获取对LoginView控件中包含的控件的引用,请使用LoginView控件的FindContol方法。
TextBox tb = lcLoginView.FindControl("txtEventNote") as TextBox
if (tb != null)
{
tb.Text = "My New Value For This TextBox control";
}
Do the same for your DropDownList
.
对下拉列表也一样。
I found In Search Of ASP.Net Controls to be helpful for more about finding ASP.NET controls in other ASP.NET controls.
我在寻找ASP。Net控件有助于更多地找到ASP。NET控件在其他ASP中。网络控制。