Groups | Blog | Home
all groups > asp.net > march 2007 >

asp.net : AJAX Dropdown extender & Gridview


William Youngman
3/10/2007 8:29:58 PM
I have a gridview displaying data and would like to use the AJAX =
dropdown extender so that when the user clicks on a record a dropdown =
menu will display providing the user with a menu of selections to choose =
from (yes much like the SharePoint 2007 dropdown menu).

I'm having problems dynamically binding the 'TargetControlID' property =
of the extender control to the record label in the gridview.

What I'm doing is -

The label's text is the record number for the user to choose from.
AJ_Dropdown is the AJAX Dropdown Extender control

I'm getting a run-time error stating 'The TargetControlID of =
AJ_DropDown' is not valid. A control with ID 'PIDP3 - #3' could not be =
found.'

//Pseudocode
Code called in the ItemDataBound method of the gridview
if (e.Item is GridViewItem)

{

GridViewItemDataItem =3D e.Item as GridViewItem;

Label label =3D (Label)DataItem.FindControl("lblPID");

if (label !=3D null)

{

label.ID =3D "PID" + label.Text;

AJ_DropDown.TargetControlID =3D label.ID; -- Proposal number for current =
row

}

}

Can't figure out what I'm doing wrong.

Any suggestions/ideas?

Thanks,

Roland Dick
3/12/2007 12:00:00 AM
William Youngman schrieb:

[quoted text, click to view]

Hi Bill,

I'm fairly new to ASP.NET and I might be completely wrong on this, but
why would you set the ID of the label? Shouldn't it be retrieving the
complete ID (which is I think something made up from the gridview ID,
the row ID and the label ID itself and should be stored in the property
ClientID) and assigning that to TargetControlID?

As another approach, try to convert the column with the record label to
a TemplateColumn (if it isn't yet), then you should be able to
declaratively bind the label ID. Here's a snippet of what worked for me:

<asp:TemplateField>
<ItemTemplate>
<ajaxControls:ConfirmButtonExtender ID="cbe" runat="server"
TargetControlID="lbtnDelete" ConfirmText="Really delete?" />
<asp:LinkButton ID="lbtnDelete" runat="server"
CausesValidation="False" CommandName="Delete" Text="Löschen">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>

(This is assuming that you want the drop down list to be displayed in
the gridview, maybe in an EditItemTemplate instead of the ItemTemplate
above.)

Hope this helps,

Cheers,
AddThis Social Bookmark Button