AJAX Dropdown extender & Gridview

W

William Youngman

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 = e.Item as GridViewItem;

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

if (label != null)

{

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

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

}

}

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

Any suggestions/ideas?

Thanks,

Bill Youngman
 
R

Roland Dick

William said:
Code called in the ItemDataBound method of the gridview

/if (e.Item is GridViewItem)/

/{/

/GridViewItemDataItem = e.Item as GridViewItem;/

/Label label = (Label)DataItem.FindControl("lblPID");/

/if (label != null)/

/{/

/label.ID = "PID" + label.Text;/

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

/}/

/}/

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,
Roland
 

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

Top