Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Accessing FormView template controls

Reply
Thread Tools

Accessing FormView template controls

 
 
Arturo Buonanni
Guest
Posts: n/a
 
      04-04-2006
Hello,

I've a question about how to access FormView template controls.

I've some dropdownlist controls in the EditItem template of a FormView
control. These dropdownlist controls are populated by database table
and the dropdownlist's SelectedValue property is bound to fields in
another table. These fields may be null.

Now, when the EditItem template is used with a record that has null
values in the field bound to the dropdownlist's SelectedValue property
an error is raised cause the dropdownlist doesn't have a value for the
"null" field to be selected.

As for what I know there are two way to address this issue: add a
record with the null value on the tables that populates the
dropdownlists or programmatically add an empty item to the
dropdownlists.

I would prefer the second option (I don't like null values in table
key fields) but I can't find the event that gives me access to the
FormView's EditItem template controls so to add the empty items before
the dropdownlist controls are bound to their fields.

Is there a way to do that?

Thanks for your help.
 
Reply With Quote
 
 
 
 
Phillip Williams
Guest
Posts: n/a
 
      04-04-2006
This demo would explain to you the strategies on both the FormView and the
GridView:
http://www.webswapp.com/codesamples/...s/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"Arturo Buonanni" wrote:

> Hello,
>
> I've a question about how to access FormView template controls.
>
> I've some dropdownlist controls in the EditItem template of a FormView
> control. These dropdownlist controls are populated by database table
> and the dropdownlist's SelectedValue property is bound to fields in
> another table. These fields may be null.
>
> Now, when the EditItem template is used with a record that has null
> values in the field bound to the dropdownlist's SelectedValue property
> an error is raised cause the dropdownlist doesn't have a value for the
> "null" field to be selected.
>
> As for what I know there are two way to address this issue: add a
> record with the null value on the tables that populates the
> dropdownlists or programmatically add an empty item to the
> dropdownlists.
>
> I would prefer the second option (I don't like null values in table
> key fields) but I can't find the event that gives me access to the
> FormView's EditItem template controls so to add the empty items before
> the dropdownlist controls are bound to their fields.
>
> Is there a way to do that?
>
> Thanks for your help.
>

 
Reply With Quote
 
 
 
 
Arturo Buonanni
Guest
Posts: n/a
 
      04-05-2006
Thanks for the demo. It's apreciated but it doesn't address my issues.
In the demo there's only one dropdownlist control bound to a data
field:

<aspropDownList ID="ddlCountry" runat="server"
DataSourceID="odsCountries" AutoPostBack="True"
SelectedValue='<%# Bind("Country") %>'>
</aspropDownList>

and the sample doesn't carry any code related to this control.

All my dropdownlist controls are bound to data fields and when the
bound data field is null I get this error:
'ddlCountry' has a SelectedValue which is invalid because it does not
exist in the list of items. Parameter name: value

Anyway I solved the issue by adding a row with the null value to the
datatable returned by the code objects I use as data source.

Thanks for the help.

On Tue, 4 Apr 2006 15:55:01 -0700, Phillip Williams
<(E-Mail Removed)> wrote:

>This demo would explain to you the strategies on both the FormView and the
>GridView:
>http://www.webswapp.com/codesamples/...s/default.aspx

 
Reply With Quote
 
Phillip Williams
Guest
Posts: n/a
 
      04-05-2006
Actually there are 3 databound dropdownlists control in the sample. The
source code is available from the tab at the bottom of the page (if you have
scrolled to the end of the page). I examined 4 different solutions on the
tab titled "GridView" at the bottom.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"Arturo Buonanni" wrote:

> Thanks for the demo. It's apreciated but it doesn't address my issues.
> In the demo there's only one dropdownlist control bound to a data
> field:
>
> <aspropDownList ID="ddlCountry" runat="server"
> DataSourceID="odsCountries" AutoPostBack="True"
> SelectedValue='<%# Bind("Country") %>'>
> </aspropDownList>
>
> and the sample doesn't carry any code related to this control.
>
> All my dropdownlist controls are bound to data fields and when the
> bound data field is null I get this error:
> 'ddlCountry' has a SelectedValue which is invalid because it does not
> exist in the list of items. Parameter name: value
>
> Anyway I solved the issue by adding a row with the null value to the
> datatable returned by the code objects I use as data source.
>
> Thanks for the help.
>
> On Tue, 4 Apr 2006 15:55:01 -0700, Phillip Williams
> <(E-Mail Removed)> wrote:
>
> >This demo would explain to you the strategies on both the FormView and the
> >GridView:
> >http://www.webswapp.com/codesamples/...s/default.aspx

>

 
Reply With Quote
 
Dabbler
Guest
Posts: n/a
 
      04-14-2006
Phillip I'm having the same problem with selected value no t in list. I looked over your code and implemented the DataBound method but I get the exception before the ddl's DataBound method is called. I've tried every event of the ddl to see when its happening but the binding to the FormView's objectdatasource must be happening first

Any suggestions would be appreciated
protected void ddlOfficePark_DataBound( Object sender, EventArgs e )
DropDownList ddl = sender as DropDownList
ddl.Items.Insert( 0, new ListItem( "Choose an Office Complex", "0" ) );
FormViewRow fvRow = (FormViewRow)ddl.NamingContainer
DataRowView drv = (DataRowView)fvRegDetail.DataItem
if ( drv != null )
string strOfficeParkId = drv["OfficeParkId"].ToString()
ddl.ClearSelection()
ListItem li = ddl.Items.FindByValue(strOfficeParkId )
if ( li != null ) li.Selected = true




Any suggestions would be appreciated

---
Posted via www.DotNetSlackers.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing controls in FormView justin ASP .Net 0 07-31-2007 07:08 PM
Accessing the controls in the PagerTemplate when using FormView Nathan Sokalski ASP .Net 0 01-11-2007 06:19 AM
Accessing the controls in the PagerTemplate when using FormView Nathan Sokalski ASP .Net Web Controls 0 01-11-2007 06:19 AM
Accessing the controls in the PagerTemplate when using FormView Nathan Sokalski ASP .Net Datagrid Control 0 01-11-2007 06:19 AM
accessing formview controls Horace Nunley ASP .Net 1 08-28-2006 05:02 AM



Advertisments