SqlDataSource ControlParameter from DetailsView dropdownlist

K

K B

Hi,

I've tried this several ways but get the error that the control can't be
found.

I have a details view with a dropdownlist in the EditItemTemplate
populated and assigned the selected value in code.

I need to get the selected value when the record is saved. I've tried
using the following in the SqlDataSource updating event:

Dim sWF As String = (CType(dvAddProcess.FindControl("ddlWfEdit"),
DropDownList)).SelectedValue
e.Command.Parameters("@WorkFlowDoc").Value = sWF

I've also tried adding a ControlParameter to the SqlDataSource Update
parameters list:

<asp:ControlParameter ControlID="dvAddProcess$ddlWfEdit" Type="string"
Name="WorkFlowDoc" PropertyName="SelectedValue" />

Could anyone tell me where I'm going wrong?

thanks,
KB
 
S

Shawn Wildermuth

Hello K,

The problem most likely is that the FindControl doesn't do a good job of
going down a hierarchy until it finds the control. I use this little utility
function to find FormView controls (sorry for the C#, but hopefully you can
convert it):

public static Control FindControl(Control parent, string id)
{
if (parent != null && parent.Controls != null && parent.Controls.Count
!= 0)
{

Control ctrl = parent.FindControl(id);
if (ctrl != null)
{
return ctrl;
}
else
{
foreach (Control subCtrl in parent.Controls)
{
ctrl = FindControl(subCtrl, id);
if (ctrl != null) return ctrl;
}
}
}

return null;
}


Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP
 
K

K B

Shawn,

It's a little over my head to see where I apply this. Any ideas why I
can't use the ControlParemeter because that way I can specify the
control name AND the parent control? But it isn't found.

<asp:ControlParameter ControlID="dvAddProcess$ddlWfInsert" Type="string"
Name="WorkFlowDoc" PropertyName="SelectedValue" />

Thanks for responding!

K
 
S

Shawn Wildermuth

Hello K,

As far as I know, this doesn't work because it can't parse the dvAddProcess$ddlWfInsert
to figure out what you mean is the ddlWfInsert control inside the DetailsView.
So you need to do it on the DataSource's Selecting event.


Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top