|
 |
aspx thread: PlaceHolder control in an EditItemTemplate
Message #1 by bmcelhany@h... on Sat, 14 Dec 2002 04:26:22
|
|
Hello,
I have a DataList control that is bound to a DataSet that contains 3
fields. In the EditItemTemplate, the first and second fields are displayed
in standard text boxes. The problem is with the third field. Depending on
the value in this field, I may need to use a RadioButtonList or a TextBox.
I figured I'd just put a PlaceHolder control in the EditItemTemplate, and
then in the EditCommand event handler I'd dynamically add the appropriate
control. As a test, I just tried to add a TextBox control. I'm using the
following code:
public void lstQuestions_EditCommand(object source,
DataListCommandEventArgs e)
{
lstQuestions.EditItemIndex = e.Item.ItemIndex;
lstQuestions.SelectedIndex = e.Item.ItemIndex;
PlaceHolder plhOptions = (PlaceHolder)lstQuestions.FindControl
("plhOptions");
TextBox t = new TextBox();
plhOptions.Controls.Add(t);
bindData();
}
The line where I add the TextBox to the PlaceHolder raises the following
error: Exception Details: System.NullReferenceException: Object reference
not set to an instance of an object.
Am I adding this code to the wrong section, or is it some sort of syntax
error? Thanks for any help you can provide!
Brian
Message #2 by "jayathakar" <jayathakar@y...> on Sun, 15 Dec 2002 07:18:59
|
|
Use (PlaceHolder)lstQuestions.item(e.Item.ItemIndex).FindControl
("plhOptions");
--Regards
Jaya
> Hello,
> I have a DataList control that is bound to a DataSet that contains 3
f> ields. In the EditItemTemplate, the first and second fields are
displayed
i> n standard text boxes. The problem is with the third field. Depending
on
t> he value in this field, I may need to use a RadioButtonList or a
TextBox.
> I figured I'd just put a PlaceHolder control in the EditItemTemplate,
and
t> hen in the EditCommand event handler I'd dynamically add the
appropriate
c> ontrol. As a test, I just tried to add a TextBox control. I'm using
the
f> ollowing code:
> public void lstQuestions_EditCommand(object source,
D> ataListCommandEventArgs e)
{>
l> stQuestions.EditItemIndex = e.Item.ItemIndex;
l> stQuestions.SelectedIndex = e.Item.ItemIndex;
P> laceHolder plhOptions = (PlaceHolder)lstQuestions.FindControl
(> "plhOptions");
T> extBox t = new TextBox();
p> lhOptions.Controls.Add(t);
b> indData();
}>
> The line where I add the TextBox to the PlaceHolder raises the
following
e> rror: Exception Details: System.NullReferenceException: Object
reference
n> ot set to an instance of an object.
> Am I adding this code to the wrong section, or is it some sort of
syntax
e> rror? Thanks for any help you can provide!
> Brian
|
|
 |