FindControl in FormView

  • Thread starter Thread starter Arthur.Net
  • Start date Start date
A

Arthur.Net

I am having trouble finding a checkbox control within a formview. I
can find other textboxes and such in here. Any ideas?

Here is the form simplified:

<asp:FormView ID="formCategory" runat="server"
DataSourceID="dsCategoryForm">
<ItemTemplate>
<asp:CheckBoxList ID="chkUDF" runat="server"
DataSourceID="dsUDFchk" DataTextField="FieldNameStr"
DataValueField="BaseUDFID"></asp:CheckBoxList>
</ItemTemplate>
</asp:FormView>

Here is the code that runs:
CheckBoxList _chkUDF =
(CheckBoxList)formCategory.FindControl("chkUDF");

foreach (ListItem chk in _chkUDF.Items)
{
chk.Selected = false;
}
 
I am having trouble finding a checkbox control within a formview. I
can find other textboxes and such in here. Any ideas?

Here is the form simplified:

<asp:FormView ID="formCategory" runat="server"
DataSourceID="dsCategoryForm">
<ItemTemplate>
<asp:CheckBoxList ID="chkUDF" runat="server"
DataSourceID="dsUDFchk" DataTextField="FieldNameStr"
DataValueField="BaseUDFID"></asp:CheckBoxList>
</ItemTemplate>
</asp:FormView>

Here is the code that runs:
CheckBoxList _chkUDF =
(CheckBoxList)formCategory.FindControl("chkUDF");

foreach (ListItem chk in _chkUDF.Items)
{
chk.Selected = false;

}

look at the rendered html.
If i remember correctly , i think something is append to the control
name..
that mite be the reason why you cant find it.
 
I am having trouble finding a checkbox control within a formview.  I
can find other textboxes and such in here.  Any ideas?

Here is the form simplified:

<asp:FormView ID="formCategory" runat="server"
DataSourceID="dsCategoryForm">
   <ItemTemplate>
      <asp:CheckBoxList ID="chkUDF" runat="server"
DataSourceID="dsUDFchk" DataTextField="FieldNameStr"
DataValueField="BaseUDFID"></asp:CheckBoxList>
   </ItemTemplate>
</asp:FormView>

Here is the code that runs:
CheckBoxList _chkUDF =
(CheckBoxList)formCategory.FindControl("chkUDF");

foreach (ListItem chk in _chkUDF.Items)
{
chk.Selected = false;



}- Hide quoted text -

- Show quoted text -

Hi,

The control is renamed based on each row. It's easy to see that there
will be one control per row, so all of them cannot be named the same.
What is what you want to do?
There might be a better way of doing it
 
Hi,

The control is renamed based on each row. It's easy to see that there
will be one control per row, so all of them cannot be named the same.
What is what you want to do?
There might be a better way of doing it

It is not failing on the loop. That works in many previous
incarnations. It says it is failing because this part is not finding
anything..
CheckBoxList _chkUDF =
(CheckBoxList)formCategory.FindControl("chkUDF");

I am sure there are many better ways, but I have been programming .Net
for exactly one week.
 
It is not failing on the loop.  That works in many previous
incarnations.  It says it is failing because this part is not finding
anything..
CheckBoxList _chkUDF =
(CheckBoxList)formCategory.FindControl("chkUDF");

I am sure there are many better ways, but I have been programming .Net
for exactly one week.- Hide quoted text -

- Show quoted text -

That is what I meant, each Row has an isntance of that control, of
course that each particular contorl has a different name.
Take a look at the code of the page. you will see the real name of the
control.

In response of what event you are running tht code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top