I am trying to obtain the SelectedValue from a DropDownList which is controlled by a CascadingDropDown Control both of which are inside of a gridview. The cascading dropdowns are populating correctly. The SelectedValue is also set on these dropdowns in the OnRowDataBound event.
In the OnRowUpdating event, I am grabbing the dropdownlist's selected value from the updating row using:
string strID = ((
DropDownList)gvPositions.Rows[e.RowIndex].FindControl("ddlLineEdit")).SelectedValue;When I do this, the value is always null.
I think it might be because you don't reference the cell but only the row. I have a similar example that does work:DropDownList ddPanes = (DropDownList)grid.Rows[e.RowIndex].Cells[2].FindControl("ddPaneNames");
Hope it helps,
Joe
That was a good thought. I don't have to do that for the other controls in the row, but I tried it. Unfortunately that still give me null as well.
Can you post the markup for your gridview?
Here is my code:
<asp:GridView ID="gvPositions" runat="server" AutoGenerateColumns="False" Width="100%" OnRowEditing="gvEdit" OnRowCancelingEdit="gvCancel" OnRowUpdating="gvUpdate" OnRowCommand="gvItemCommand" OnRowDeleting="gvDelete" OnRowDataBound="gvRowDataBind"> <Columns> <asp:TemplateField HeaderText="positionID" Visible="False"> <ItemTemplate> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.positionID")%>' ID="lblpositionID"> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.positionID")%>' ID="lblpositionID"> </asp:Label> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="TDA Version"> <ItemTemplate> <asp:Label runat="server" Text='<%# Eval("tdaName")%>' ID="lbltdaNameGrid"> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:Label runat="server" ID="lbltdaNameEdit" CssClass="label" Width="100%" Text='<%# DataBinder.Eval(Container, "DataItem.tdaName")%>'> </asp:Label> <asp:DropDownList ID="ddlTDANameEdit" runat="server" AutoPostBack="false" DataSource='<%# GetTDAList()%>' SelectedValue='<%# Eval("tdaVersionID")%>' DataTextField="tdaName" DataValueField="tdaVersionID" ></asp:DropDownList> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Paragraph"> <ItemTemplate> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.paragraphTitle")%>' ID="lblParagraphNameGrid"> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:Label runat="server" ID="lblParagraphEdit" CssClass="label" Width="100%" Text='<%# DataBinder.Eval(Container, "DataItem.paragraphTitle")%>'> </asp:Label> <asp:DropDownList ID="ddlParagraphEdit" runat="server" AutoPostBack="false"></asp:DropDownList> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Line"> <ItemTemplate> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.lineTitle")%>' ID="lbltitleGrid"> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:Label runat="server" ID="lbltitleEdit" CssClass="label" Width="100%" Text='<%# DataBinder.Eval(Container, "DataItem.lineTitle")%>'> </asp:Label> <asp:DropDownList ID="ddlLineEdit" runat="server" AutoPostBack="false"></asp:DropDownList> <cc1:CascadingDropDown ID="CascadingDropDownGridView" runat="server" SuppressValidationScript="true"> <cc1:CascadingDropDownProperties TargetControlID="ddlParagraphEdit" ServiceMethod="GetParagraphsByTDAID" ServicePath="~/AutoCompleteService.asmx" PromptText="Please select a paragraph" Category="tdaVersionID" ParentControlID="ddlTDANameEdit" /> <cc1:CascadingDropDownProperties TargetControlID="ddlLineEdit" ServiceMethod="GetLinesByParagraphID" ServicePath="~/AutoCompleteService.asmx" PromptText="Please select a line" Category="tdaParagraphID" ParentControlID="ddlParagraphEdit" /> </cc1:CascadingDropDown> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Directorate"> <ItemTemplate> <asp:Label runat="server" ID="lblDirectorate" Text='<%# DataBinder.Eval(Container, "DataItem.directorateSymbol")%>' width="100%"> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList runat="server" id="ddlDirectorate" CssClass="label" Width="100%" DataSource='<%# GetDirectorateList()%>' SelectedIndex='<%# GetSelectedDirectorate(DataBinder.Eval(Container, "DataItem.directorateID").ToString())%>' DataTextField="directorateSymbol" DataValueField="directorateID"> </asp:DropDownList> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Division" ControlStyle-Width="100px"> <ItemTemplate> <asp:Label runat="server" ID="lblDivision" Text='<%# DataBinder.Eval(Container, "DataItem.officeSymbol")%>' width="100%"> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList runat="server" id="ddlDivision" CssClass="label" Width="100%" DataSource='<%# GetDivisionList()%>' SelectedIndex='<%# GetSelectedDivision(DataBinder.Eval(Container, "DataItem.divisionID").ToString())%>' DataTextField="officeSymbol" DataValueField="divisionID"> </asp:DropDownList> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Start Date
<ItemTemplate> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.dateStartText")%>' ID="lblGridDateStart"> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox runat="server" ID="txtGridDateStart" CssClass="label" Width="100%" Text='<%# DataBinder.Eval(Container, "DataItem.dateStartText")%>'> </asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="End Date
<ItemTemplate> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.dateEndText")%>' ID="lblGridDateEnd"> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox runat="server" ID="txtGridDateEnd" CssClass="label" Width="100%" Text='<%# DataBinder.Eval(Container, "DataItem.dateEndText")%>'> </asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Current Position"> <ItemTemplate> <asp:CheckBox ID="chkbxPositionCurrentDisplay" runat="server" Checked='<%# DataBinder.Eval(Container, "DataItem.positionCurrent")%>' Enabled="false" /> </ItemTemplate> <EditItemTemplate> <asp:CheckBox ID="chkbxPositionCurrent" runat="server" Checked='<%# DataBinder.Eval(Container, "DataItem.positionCurrent")%>' /> </EditItemTemplate> </asp:TemplateField> <asp:CommandField ShowEditButton="True" CancelImageUrl="~/images/cancel.gif" ShowDeleteButton="True" DeleteImageUrl="~/images/delete.gif" EditImageUrl="~/images/edit.gif" UpdateImageUrl="~/images/save.gif" ButtonType="Image" /> </Columns> </asp:GridView>
The code I listed above us on a Web User Control called by another Web User Control which is called by a Web Form. I recreated the Gridview on a new page this morning with all the code behind and it worked.
So I am wondering if this has to do with when the Page_Load get called for each control. I would really like to get it to work on the control.
Could this be a symptom the cause of work item 640?
No comments:
Post a Comment