Answered by:
Gridview Edit has a SelectedValue which is invalid because it does not exist in the list of items.

Question
-
I have been banging my head over this for couple weeks now. I started coding this practice project in VB then yesterday decided to recode this in CSharp to see if the problem still exists which it does. My cascadingdropdownlist throws this error and I cant for the life of me find anywhere that actually has a concrete solution to this issue. I have tried numerous things that I read and all of them have failed me.
Basically I have a gridview that is populated with my objectdatasource which gets filled with my databasecomponet class. If i was to click Insert on my gridview my cascading dropdownlist work great the values appear as they should I can submit it to the database and everything works.
Now the problem happens when I want to just edit a record it throws
'ddlgvRoom' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: 'ddlgvRoom' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [ArgumentOutOfRangeException: 'ddlgvRoom' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value] System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable dataSource) +1765625 System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +109 System.Web.UI.WebControls.ListControl.PerformSelect() +34 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74 System.Web.UI.Control.DataBindChildren() +201 System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101 System.Web.UI.Control.DataBind() +15 System.Web.UI.Control.DataBindChildren() +201 System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101 System.Web.UI.Control.DataBind() +15 System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +166 System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +3896 System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +66 System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74 System.Web.UI.WebControls.GridView.DataBind() +4 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66 System.Web.UI.WebControls.GridView.OnPreRender(EventArgs e) +26 System.Web.UI.Control.PreRenderRecursiveInternal() +103 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
That error. I am desperate to figure out how to fix this I am assuming from what I have been reading that they want me to find the dropdownlist in the gridview and populate it through the code behind However I am lost on how to approach that.
Here is my webservice code which populates the dropdownlist but this works during insert mode
[WebMethod] public CascadingDropDownNameValue[] GetRooms(string knownCategoryValues, string category) { dsRoomsTableAdapters.RoomTableAdapter roomAdapter = new dsRoomsTableAdapters.RoomTableAdapter(); dsRooms.RoomsDataTable rooms = roomAdapter.GetAllRooms(); List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); foreach (DataRow dr in rooms) { string room = (string)dr["RoomName"]; int roomid = (int)dr["intRoom"]; values.Add(new CascadingDropDownNameValue(room, roomid.ToString())); } return values.ToArray(); } [WebMethod] public CascadingDropDownNameValue[] GetJacks(string knownCategoryValues, string category) { StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); int roomid; if (!kv.ContainsKey("Jack") || !Int32.TryParse(kv["Jack"], out roomid)) { return null; } dsJacksTableAdapters.JacksByRoomIDTableAdapter jackAdapter = new dsJacksTableAdapters.JacksByRoomIDTableAdapter(); dsJacks.JacksByRoomIDDataTable jacks = jackAdapter.GetJacksByRoomid(roomid); List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); foreach (DataRow dr in jacks) { values.Add(new CascadingDropDownNameValue((string)dr["JackNumber"], dr["intJack"].ToString())); } return values.ToArray(); } }
Gridview Dropdownlist code</asp:DropDownList> <asp:CascadingDropDown ID="ddlgvRoom_CascadingDropDown" runat="server" Enabled="True" TargetControlID="ddlgvRoom" Category="Jack" ServiceMethod="GetRooms" ServicePath="cascadingddl.asmx" LoadingText="[Loading Rooms...]" PromptText="Please Select Room"> </asp:CascadingDropDown> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lblgvRoom" runat="server" Text='<%# Eval("IntRoom") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="JackNumber" SortExpression="IntJack"> <EditItemTemplate> <asp:DropDownList ID="ddlgvJack" runat="server" DataTextField="JackNumber" DataValueField="intJack" Text='<%# Bind("IntJack") %>' > <asp:ListItem></asp:ListItem> </asp:DropDownList> <asp:CascadingDropDown ID="ddlgvJack_CascadingDropDown" runat="server" Enabled="True" TargetControlID="ddlgvJack" Category="Jack" LoadingText="[Loading Jacks...]" ServiceMethod="GetJacks" ServicePath="cascadingddl.asmx" ParentControlID="ddldvRoom" PromptValue="Please Select A Jack"> </asp:CascadingDropDown> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lblgvJack" runat="server" Text='<%# Bind("IntJack") %>'></asp:Label> </ItemTemplate>
If anyone can help please I am desperate tried couple other forums and nobody seems to want to help must be more than a headache than its worth but I am at a dead end and really want to figure this out. If you need more of my code I will be happy to post it i have MSSQL Stored procedures but they all run fine as this does work Just not in editmode.
Thanks
- Moved by Dummy yoyo Tuesday, September 27, 2011 2:57 PM (From:Visual C# General)
Sunday, September 18, 2011 12:13 AM
Answers
-
Maybe your gridview is not populated with the same values between postbacks.
I think you'll get better answer in the ASP forum.
- Proposed as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:57 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:59 AM
Monday, September 19, 2011 8:31 AM -
Hi
I made some changes in your code. Please try this. I didn't get the time to complete it. You may get some hints from this.
//HTML <%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" AutoEventWireup="true" %> <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:scriptmanager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="cascadingddl.asmx" /> </Services> </asp:scriptmanager> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="sourceGroups" Height="50px" Width="275px"> <Fields> <asp:BoundField DataField="GroupID" HeaderText="GroupID" SortExpression="GroupID" InsertVisible="False" /> <asp:BoundField DataField="UserInitials" HeaderText="UserInitials" SortExpression="UserInitials" /> <asp:BoundField DataField="GroupName" HeaderText="GroupName" SortExpression="GroupName" /> <asp:TemplateField HeaderText="StartDate" SortExpression="StartDate"> <InsertItemTemplate> <asp:TextBox ID="txtdvStartDate" runat="server" Text='<%# Bind("StartDate") %>' Height="20px" Width="70px"></asp:TextBox> <asp:CalendarExtender ID="txtdvStartDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtdvStartDate"> </asp:CalendarExtender> <asp:DropDownList ID="ddldvStartTime" runat="server" SelectedValue='<%# Bind("StartTime") %>'> <asp:ListItem Value="12:00AM">12:00AM</asp:ListItem> <asp:ListItem Value="1:00AM">1:00AM</asp:ListItem> <asp:ListItem Value="2:00AM">2:00AM</asp:ListItem> <asp:ListItem Value="3:00AM">3:00AM</asp:ListItem> <asp:ListItem Value="4:00AM">4:00AM</asp:ListItem> <asp:ListItem Value="5:00AM">5:00AM</asp:ListItem> <asp:ListItem Value="6:00AM">6:00AM</asp:ListItem> <asp:ListItem Value="7:00AM">7:00AM</asp:ListItem> <asp:ListItem Value="8:00AM">8:00AM</asp:ListItem> <asp:ListItem Value="9:00AM">9:00AM</asp:ListItem> <asp:ListItem Value="10:00AM">10:00AM</asp:ListItem> <asp:ListItem Value="11:00AM">11:00AM</asp:ListItem> <asp:ListItem Value="12:00PM">12:00PM</asp:ListItem> <asp:ListItem Value="1:00PM">1:00PM</asp:ListItem> <asp:ListItem Value="2:00PM">2:00PM</asp:ListItem> <asp:ListItem Value="3:00PM">3:00PM</asp:ListItem> <asp:ListItem Value="4:00PM">4:00PM</asp:ListItem> <asp:ListItem Value="5:00PM">5:00PM</asp:ListItem> <asp:ListItem Value="6:00PM">6:00PM</asp:ListItem> <asp:ListItem Value="7:00PM">7:00PM</asp:ListItem> <asp:ListItem Value="8:00PM">8:00PM</asp:ListItem> <asp:ListItem Value="9:00PM">9:00PM</asp:ListItem> <asp:ListItem Value="10:00PM">10:00PM</asp:ListItem> <asp:ListItem Value="11:00PM">11:00PM</asp:ListItem> </asp:DropDownList> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="lbldvStartDate" runat="server" Text='<%# Bind("StartDate") %>'></asp:Label> <asp:Label ID="lbldvStartTime" runat="server" Text='<%# Bind("StartTime") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="EndDate" SortExpression="EndDate"> <EditItemTemplate> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="txtdvEndDate" runat="server" Text='<%# Bind("EndDate") %>' Height="20px" Width="69px"></asp:TextBox> <asp:CalendarExtender ID="txtdvEndDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtdvEndDate"> </asp:CalendarExtender> <asp:DropDownList ID="ddldvEndTime" runat="server" SelectedValue='<%# Bind("EndTime") %>'> <asp:ListItem Value="12:00AM">12:00AM</asp:ListItem> <asp:ListItem Value="1:00AM">1:00AM</asp:ListItem> <asp:ListItem Value="2:00AM">2:00AM</asp:ListItem> <asp:ListItem Value="3:00AM">3:00AM</asp:ListItem> <asp:ListItem Value="4:00AM">4:00AM</asp:ListItem> <asp:ListItem Value="5:00AM">5:00AM</asp:ListItem> <asp:ListItem Value="6:00AM">6:00AM</asp:ListItem> <asp:ListItem Value="7:00AM">7:00AM</asp:ListItem> <asp:ListItem Value="8:00AM">8:00AM</asp:ListItem> <asp:ListItem Value="9:00AM">9:00AM</asp:ListItem> <asp:ListItem Value="10:00AM">10:00AM</asp:ListItem> <asp:ListItem Value="11:00AM">11:00AM</asp:ListItem> <asp:ListItem Value="12:00PM">12:00PM</asp:ListItem> <asp:ListItem Value="1:00PM">1:00PM</asp:ListItem> <asp:ListItem Value="2:00PM">2:00PM</asp:ListItem> <asp:ListItem Value="3:00PM">3:00PM</asp:ListItem> <asp:ListItem Value="4:00PM">4:00PM</asp:ListItem> <asp:ListItem Value="5:00PM">5:00PM</asp:ListItem> <asp:ListItem Value="6:00PM">6:00PM</asp:ListItem> <asp:ListItem Value="7:00PM">7:00PM</asp:ListItem> <asp:ListItem Value="8:00PM">8:00PM</asp:ListItem> <asp:ListItem Value="9:00PM">9:00PM</asp:ListItem> <asp:ListItem Value="10:00PM">10:00PM</asp:ListItem> <asp:ListItem Value="11:00PM">11:00PM</asp:ListItem> </asp:DropDownList> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="lbldvEndDate" runat="server" Text='<%# Bind("EndDate") %>'></asp:Label> <asp:Label ID="lbldvEndTime" runat="server" Text='<%# Bind("EndTime") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="RoomName" SortExpression="IntRoom"> <InsertItemTemplate> <asp:DropDownList ID="ddldvRoom" runat="server" DataTextField="RoomName" DataValueField="intRoom" Text='<%# Bind("IntRoom") %>' > </asp:DropDownList> <asp:CascadingDropDown ID="ddldvRoom_CascadingDropDown" runat="server" Enabled="True" TargetControlID="ddldvRoom" Category="Jack" ServiceMethod="GetRooms" ServicePath="cascadingddl.asmx" LoadingText="[Loading Rooms...]" PromptText="Please Select Room"> </asp:CascadingDropDown> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="lbldvRoom" runat="server" Text='<%# Eval("IntRoom") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="JackNumber" SortExpression="IntJack"> <InsertItemTemplate> <asp:DropDownList ID="ddldvJack" runat="server" DataTextField="JackNumber" DataValueField="intJack" Text='<%# Bind("IntJack") %>' > </asp:DropDownList> <asp:CascadingDropDown ID="ddldvJack_CascadingDropDown" runat="server" Enabled="True" TargetControlID="ddldvJack" Category="Jack" LoadingText="[Loading Jacks...]" ServiceMethod="GetJacks" ServicePath="cascadingddl.asmx" ParentControlID="ddldvRoom" PromptValue="Please Select A Jack"> </asp:CascadingDropDown> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="lbldvJack" runat="server" Text='<%# Eval("IntJack") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Internet Type" SortExpression="VlanID"> <InsertItemTemplate> <asp:DropDownList ID="ddldvVlan" runat="server" DataSourceID="sourceVlan1" DataTextField="InternetType" DataValueField="VlanID" Text='<%# Bind("VlanID") %>'> </asp:DropDownList> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="lbldvVlan" runat="server" Text='<%# Eval("VlanID") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="UserComments" SortExpression="UserComments"> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("UserComments") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("UserComments") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("UserComments") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:CommandField ShowInsertButton="True" /> </Fields> </asp:DetailsView> <br /><br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="sourceGroups" OnRowUpdating="GridView1_RowUpdating"> <Columns> <asp:BoundField DataField="GroupID" HeaderText="GroupID" SortExpression="GroupID" /> <asp:BoundField DataField="UserInitials" HeaderText="UserInitials" SortExpression="UserInitials" /> <asp:BoundField DataField="GroupName" HeaderText="GroupName" SortExpression="GroupName" /> <asp:TemplateField HeaderText="StartDate/StartTime" SortExpression="StartDate"> <EditItemTemplate> <asp:TextBox ID="txtgvStartDate" runat="server" Text='<%# Bind("StartDate") %>' Height="20px" Width="70px"></asp:TextBox> <asp:CalendarExtender ID="txtgvStartDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtgvStartDate"> </asp:CalendarExtender> <asp:DropDownList ID="ddlgvStartTime" runat="server" Text='<%# Bind("StartTime") %>'> <asp:ListItem Value="12:00AM">12:00AM</asp:ListItem> <asp:ListItem Value="1:00AM">1:00AM</asp:ListItem> <asp:ListItem Value="2:00AM">2:00AM</asp:ListItem> <asp:ListItem Value="3:00AM">3:00AM</asp:ListItem> <asp:ListItem Value="4:00AM">4:00AM</asp:ListItem> <asp:ListItem Value="5:00AM">5:00AM</asp:ListItem> <asp:ListItem Value="6:00AM">6:00AM</asp:ListItem> <asp:ListItem Value="7:00AM">7:00AM</asp:ListItem> <asp:ListItem Value="8:00AM">8:00AM</asp:ListItem> <asp:ListItem Value="9:00AM">9:00AM</asp:ListItem> <asp:ListItem Value="10:00AM">10:00AM</asp:ListItem> <asp:ListItem Value="11:00AM">11:00AM</asp:ListItem> <asp:ListItem Value="12:00PM">12:00PM</asp:ListItem> <asp:ListItem Value="1:00PM">1:00PM</asp:ListItem> <asp:ListItem Value="2:00PM">2:00PM</asp:ListItem> <asp:ListItem Value="3:00PM">3:00PM</asp:ListItem> <asp:ListItem Value="4:00PM">4:00PM</asp:ListItem> <asp:ListItem Value="5:00PM">5:00PM</asp:ListItem> <asp:ListItem Value="6:00PM">6:00PM</asp:ListItem> <asp:ListItem Value="7:00PM">7:00PM</asp:ListItem> <asp:ListItem Value="8:00PM">8:00PM</asp:ListItem> <asp:ListItem Value="9:00PM">9:00PM</asp:ListItem> <asp:ListItem Value="10:00PM">10:00PM</asp:ListItem> <asp:ListItem Value="11:00PM">11:00PM</asp:ListItem> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lblgvStartDate" runat="server" Text='<%# Eval("StartDate") %>'></asp:Label> <asp:Label ID="lblgvStartTime" runat="server" Text='<%# Eval("StartTime") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="EndDate/EndTime" SortExpression="EndDate"> <EditItemTemplate> <asp:TextBox ID="txtgvEndDate" runat="server" Text='<%# Bind("EndDate") %>' Height="20px" Width="70px"></asp:TextBox> <asp:CalendarExtender ID="txtgvEndDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtgvEndDate"> </asp:CalendarExtender> <asp:DropDownList ID="ddlgvEndTime" runat="server" SelectedValue='<%# Bind("EndTime") %>'> <asp:ListItem Value="12:00AM">12:00AM</asp:ListItem> <asp:ListItem Value="1:00AM">1:00AM</asp:ListItem> <asp:ListItem Value="2:00AM">2:00AM</asp:ListItem> <asp:ListItem Value="3:00AM">3:00AM</asp:ListItem> <asp:ListItem Value="4:00AM">4:00AM</asp:ListItem> <asp:ListItem Value="5:00AM">5:00AM</asp:ListItem> <asp:ListItem Value="6:00AM">6:00AM</asp:ListItem> <asp:ListItem Value="7:00AM">7:00AM</asp:ListItem> <asp:ListItem Value="8:00AM">8:00AM</asp:ListItem> <asp:ListItem Value="9:00AM">9:00AM</asp:ListItem> <asp:ListItem Value="10:00AM">10:00AM</asp:ListItem> <asp:ListItem Value="11:00AM">11:00AM</asp:ListItem> <asp:ListItem Value="12:00PM">12:00PM</asp:ListItem> <asp:ListItem Value="1:00PM">1:00PM</asp:ListItem> <asp:ListItem Value="2:00PM">2:00PM</asp:ListItem> <asp:ListItem Value="3:00PM">3:00PM</asp:ListItem> <asp:ListItem Value="4:00PM">4:00PM</asp:ListItem> <asp:ListItem Value="5:00PM">5:00PM</asp:ListItem> <asp:ListItem Value="6:00PM">6:00PM</asp:ListItem> <asp:ListItem Value="7:00PM">7:00PM</asp:ListItem> <asp:ListItem Value="8:00PM">8:00PM</asp:ListItem> <asp:ListItem Value="9:00PM">9:00PM</asp:ListItem> <asp:ListItem Value="10:00PM">10:00PM</asp:ListItem> <asp:ListItem Value="11:00PM">11:00PM</asp:ListItem> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lblgvEndDate" runat="server" Text='<%# Eval("EndDate") %>'></asp:Label> <asp:Label ID="lblgvEndTime" runat="server" Text='<%# Eval("EndTime") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="UserComments" HeaderText="UserComments" SortExpression="UserComments" /> <asp:TemplateField HeaderText="RoomName" SortExpression="IntRoom"> <ItemTemplate> <asp:Label ID="lblRoom" runat="server" Text='<%#Eval("IntRoom") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddlgvRoom" runat="server"> </asp:DropDownList> <asp:CascadingDropDown ID="ddlgvRoom_CascadingDropDown" runat="server" Category="Jack" TargetControlID="ddlgvRoom" ServiceMethod="GetRooms" ServicePath="cascadingddl.asmx" LoadingText="[Loading Rooms...]" PromptText="Please Select Room"> </asp:CascadingDropDown> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="JackNumber" SortExpression="IntJack"> <ItemTemplate> <asp:Label ID="lblJack" runat="server" Text='<%#Eval("IntJack") %>'> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddlgvJack" runat="server"> </asp:DropDownList><br /> <asp:CascadingDropDown ID="ddlgvJack_CascadingDropDown" runat="server" Category="Jack" TargetControlID="ddlgvJack" ParentControlID="ddlgvRoom" PromptText="Please Select A Jack" LoadingText="[Loading Jacks...]" ServicePath="cascadingddl.asmx" ServiceMethod="GetJacks"> </asp:CascadingDropDown> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="InternetType" SortExpression="VlanID"> <ItemTemplate> <asp:Label ID="lblgvVlan" runat="server" Text='<%# Eval("VlanID") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddlgvVlan" runat="server" DataSourceID="sourceVlan1" DataTextField="InternetType" DataValueField="VlanID"> </asp:DropDownList> </EditItemTemplate> </asp:TemplateField> <asp:CommandField ShowEditButton="True" /> </Columns> </asp:GridView> <asp:ObjectDataSource ID="sourceGroups" runat="server" DataObjectTypeName="DatabaseComponent.GroupDetails" InsertMethod="InsertGroup" OldValuesParameterFormatString="original_{0}" SelectMethod="GetGroups" TypeName="DatabaseComponent.GroupDB" UpdateMethod="UpdateEmployee"> </asp:ObjectDataSource> <asp:ObjectDataSource ID="sourceVlan1" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetVlans" TypeName="dsVlansTableAdapters.GetVlansTableAdapter"></asp:ObjectDataSource> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html> //C# protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit) { DropDownList dl = (DropDownList)e.Row.FindControl("ddlgvRoom"); } } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { DropDownList ddlgvRoom = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlgvRoom"); string strgvRoom = ddlgvRoom.SelectedItem.Text.ToString(); DropDownList ddlgvJack = (DropDownList) GridView1.Rows[e.RowIndex].FindControl("ddlgvJack"); string strgvJack = ddlgvJack.SelectedItem.Text.ToString(); DropDownList ddlgvVlan = (DropDownList) GridView1.Rows[e.RowIndex].FindControl("ddlgvVlan"); string strgvVlan = ddlgvVlan.SelectedItem.Text.ToString(); }
Regards
Dominic
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful- Proposed as answer by Dominic Abraham Friday, September 23, 2011 3:56 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:58 AM
Tuesday, September 20, 2011 9:11 AM -
Hi
When i clicked on edit, i didn't get any error. I could successfully edit the values. When i clicked on update button, i could successfully read the edited values from code behind. I didn't try to update to db. You do one thing. Keep a copy of your existing code and replace the your entire code with my modified code [both html side and code behind] and try. I made different changes in your code.
For eg:
<asp:DropDownList ID="ddlgvJack" runat="server" DataTextField="JackNumber" DataValueField="intJack" Text='<%# Bind("IntJack") %>' > <asp:ListItem></asp:ListItem> </asp:DropDownList>
To<asp:DropDownList ID="ddlgvJack" runat="server"> </asp:DropDownList><br />
RegardsDominic
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful- Proposed as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:58 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:58 AM
Thursday, September 22, 2011 3:32 PM -
Hi JayJ24,
Welcome to the MSDN forum!You are more likely to get more efficient responses to ASP.NET issues at http://forums.asp.net where you can contact ASP.NET experts.
Thank you for your understanding and have a nice day,
Yoyo.
Yoyo Jiang[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:58 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:58 AM
Tuesday, September 27, 2011 2:56 PM
All replies
-
Hi
Just give a try after disable page EventValidation.
Regards
Dominic
If a post answers your question, please click "Mark As Answer" on that post and "Mark as HelpfulSunday, September 18, 2011 6:31 AM -
Hello Dominic,
Sorry did not mention that but it is already disabled. At the top of my page I have this as the cascadingdropdown list works in InsertMode just does not work in EditMode. Please help
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" enableEventValidation="false" %>
Thanks for the response
- Edited by JayJ24 Sunday, September 18, 2011 3:16 PM
Sunday, September 18, 2011 12:28 PM -
There has to be someone that knows what is going on...No matter what I search I am coming to a dead end i really need help for this one please..I wish I could solve it on my own but for the past couple weeks I have been trying and I keep running into dead ends...Help Please....
Monday, September 19, 2011 12:59 AM -
Maybe your gridview is not populated with the same values between postbacks.
I think you'll get better answer in the ASP forum.
- Proposed as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:57 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:59 AM
Monday, September 19, 2011 8:31 AM -
yea i posted over there too now but That was one of the forums that I tried and I waited 3 or 4 days and there was no response from them either. So I am not sure what i am doing wrong but would love some help....Monday, September 19, 2011 12:34 PM
-
Hi
I would like to help you. But from your given sample code, i cant guess anthing. If its simulatable here in my machine, i will try to find a solution.Just relax and think, you will get the answer.
Regards
Dominic
If a post answers your question, please click "Mark As Answer" on that post and "Mark as HelpfulMonday, September 19, 2011 12:40 PM -
Thanks Dominic
I would post the whole project but that is a lot of code and I thought it might discourage people from helping as its a lot to read through. If you would like to try it on your machine I uploaded my project to megaupload save you some time and thanks again I appreciate your help
Monday, September 19, 2011 1:33 PM -
Hi
I tried to run your project. Unfortunately it is having some build error. I think database side is failing.
Regards
Dominic
If a post answers your question, please click "Mark As Answer" on that post and "Mark as HelpfulMonday, September 19, 2011 2:11 PM -
Sorry about that completely forgot about the database here is the database which is named a_Cisco you should be able to restore it.
http://www.megaupload.com/?d=A3SZDWPB
Thanks for all your help
Monday, September 19, 2011 4:16 PM -
I tried to add the items this way but still receive same error
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if ((e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit) && (e.Row.DataItem != null)) { DropDownList dl = (DropDownList)e.Row.FindControl("ddlgvRoom") as DropDownList; dl.Items.Add(new ListItem("FirstRoom", "1")); dl.Items.Add(new ListItem("SecondRoom", "2")); dl.Items.Add(new ListItem("ThirdRoom", "3")); } }
- Edited by JayJ24 Monday, September 19, 2011 6:02 PM
Monday, September 19, 2011 5:54 PM -
Hi
I made some changes in your code. Please try this. I didn't get the time to complete it. You may get some hints from this.
//HTML <%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" AutoEventWireup="true" %> <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:scriptmanager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="cascadingddl.asmx" /> </Services> </asp:scriptmanager> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="sourceGroups" Height="50px" Width="275px"> <Fields> <asp:BoundField DataField="GroupID" HeaderText="GroupID" SortExpression="GroupID" InsertVisible="False" /> <asp:BoundField DataField="UserInitials" HeaderText="UserInitials" SortExpression="UserInitials" /> <asp:BoundField DataField="GroupName" HeaderText="GroupName" SortExpression="GroupName" /> <asp:TemplateField HeaderText="StartDate" SortExpression="StartDate"> <InsertItemTemplate> <asp:TextBox ID="txtdvStartDate" runat="server" Text='<%# Bind("StartDate") %>' Height="20px" Width="70px"></asp:TextBox> <asp:CalendarExtender ID="txtdvStartDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtdvStartDate"> </asp:CalendarExtender> <asp:DropDownList ID="ddldvStartTime" runat="server" SelectedValue='<%# Bind("StartTime") %>'> <asp:ListItem Value="12:00AM">12:00AM</asp:ListItem> <asp:ListItem Value="1:00AM">1:00AM</asp:ListItem> <asp:ListItem Value="2:00AM">2:00AM</asp:ListItem> <asp:ListItem Value="3:00AM">3:00AM</asp:ListItem> <asp:ListItem Value="4:00AM">4:00AM</asp:ListItem> <asp:ListItem Value="5:00AM">5:00AM</asp:ListItem> <asp:ListItem Value="6:00AM">6:00AM</asp:ListItem> <asp:ListItem Value="7:00AM">7:00AM</asp:ListItem> <asp:ListItem Value="8:00AM">8:00AM</asp:ListItem> <asp:ListItem Value="9:00AM">9:00AM</asp:ListItem> <asp:ListItem Value="10:00AM">10:00AM</asp:ListItem> <asp:ListItem Value="11:00AM">11:00AM</asp:ListItem> <asp:ListItem Value="12:00PM">12:00PM</asp:ListItem> <asp:ListItem Value="1:00PM">1:00PM</asp:ListItem> <asp:ListItem Value="2:00PM">2:00PM</asp:ListItem> <asp:ListItem Value="3:00PM">3:00PM</asp:ListItem> <asp:ListItem Value="4:00PM">4:00PM</asp:ListItem> <asp:ListItem Value="5:00PM">5:00PM</asp:ListItem> <asp:ListItem Value="6:00PM">6:00PM</asp:ListItem> <asp:ListItem Value="7:00PM">7:00PM</asp:ListItem> <asp:ListItem Value="8:00PM">8:00PM</asp:ListItem> <asp:ListItem Value="9:00PM">9:00PM</asp:ListItem> <asp:ListItem Value="10:00PM">10:00PM</asp:ListItem> <asp:ListItem Value="11:00PM">11:00PM</asp:ListItem> </asp:DropDownList> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="lbldvStartDate" runat="server" Text='<%# Bind("StartDate") %>'></asp:Label> <asp:Label ID="lbldvStartTime" runat="server" Text='<%# Bind("StartTime") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="EndDate" SortExpression="EndDate"> <EditItemTemplate> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="txtdvEndDate" runat="server" Text='<%# Bind("EndDate") %>' Height="20px" Width="69px"></asp:TextBox> <asp:CalendarExtender ID="txtdvEndDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtdvEndDate"> </asp:CalendarExtender> <asp:DropDownList ID="ddldvEndTime" runat="server" SelectedValue='<%# Bind("EndTime") %>'> <asp:ListItem Value="12:00AM">12:00AM</asp:ListItem> <asp:ListItem Value="1:00AM">1:00AM</asp:ListItem> <asp:ListItem Value="2:00AM">2:00AM</asp:ListItem> <asp:ListItem Value="3:00AM">3:00AM</asp:ListItem> <asp:ListItem Value="4:00AM">4:00AM</asp:ListItem> <asp:ListItem Value="5:00AM">5:00AM</asp:ListItem> <asp:ListItem Value="6:00AM">6:00AM</asp:ListItem> <asp:ListItem Value="7:00AM">7:00AM</asp:ListItem> <asp:ListItem Value="8:00AM">8:00AM</asp:ListItem> <asp:ListItem Value="9:00AM">9:00AM</asp:ListItem> <asp:ListItem Value="10:00AM">10:00AM</asp:ListItem> <asp:ListItem Value="11:00AM">11:00AM</asp:ListItem> <asp:ListItem Value="12:00PM">12:00PM</asp:ListItem> <asp:ListItem Value="1:00PM">1:00PM</asp:ListItem> <asp:ListItem Value="2:00PM">2:00PM</asp:ListItem> <asp:ListItem Value="3:00PM">3:00PM</asp:ListItem> <asp:ListItem Value="4:00PM">4:00PM</asp:ListItem> <asp:ListItem Value="5:00PM">5:00PM</asp:ListItem> <asp:ListItem Value="6:00PM">6:00PM</asp:ListItem> <asp:ListItem Value="7:00PM">7:00PM</asp:ListItem> <asp:ListItem Value="8:00PM">8:00PM</asp:ListItem> <asp:ListItem Value="9:00PM">9:00PM</asp:ListItem> <asp:ListItem Value="10:00PM">10:00PM</asp:ListItem> <asp:ListItem Value="11:00PM">11:00PM</asp:ListItem> </asp:DropDownList> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="lbldvEndDate" runat="server" Text='<%# Bind("EndDate") %>'></asp:Label> <asp:Label ID="lbldvEndTime" runat="server" Text='<%# Bind("EndTime") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="RoomName" SortExpression="IntRoom"> <InsertItemTemplate> <asp:DropDownList ID="ddldvRoom" runat="server" DataTextField="RoomName" DataValueField="intRoom" Text='<%# Bind("IntRoom") %>' > </asp:DropDownList> <asp:CascadingDropDown ID="ddldvRoom_CascadingDropDown" runat="server" Enabled="True" TargetControlID="ddldvRoom" Category="Jack" ServiceMethod="GetRooms" ServicePath="cascadingddl.asmx" LoadingText="[Loading Rooms...]" PromptText="Please Select Room"> </asp:CascadingDropDown> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="lbldvRoom" runat="server" Text='<%# Eval("IntRoom") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="JackNumber" SortExpression="IntJack"> <InsertItemTemplate> <asp:DropDownList ID="ddldvJack" runat="server" DataTextField="JackNumber" DataValueField="intJack" Text='<%# Bind("IntJack") %>' > </asp:DropDownList> <asp:CascadingDropDown ID="ddldvJack_CascadingDropDown" runat="server" Enabled="True" TargetControlID="ddldvJack" Category="Jack" LoadingText="[Loading Jacks...]" ServiceMethod="GetJacks" ServicePath="cascadingddl.asmx" ParentControlID="ddldvRoom" PromptValue="Please Select A Jack"> </asp:CascadingDropDown> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="lbldvJack" runat="server" Text='<%# Eval("IntJack") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Internet Type" SortExpression="VlanID"> <InsertItemTemplate> <asp:DropDownList ID="ddldvVlan" runat="server" DataSourceID="sourceVlan1" DataTextField="InternetType" DataValueField="VlanID" Text='<%# Bind("VlanID") %>'> </asp:DropDownList> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="lbldvVlan" runat="server" Text='<%# Eval("VlanID") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="UserComments" SortExpression="UserComments"> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("UserComments") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("UserComments") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("UserComments") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:CommandField ShowInsertButton="True" /> </Fields> </asp:DetailsView> <br /><br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="sourceGroups" OnRowUpdating="GridView1_RowUpdating"> <Columns> <asp:BoundField DataField="GroupID" HeaderText="GroupID" SortExpression="GroupID" /> <asp:BoundField DataField="UserInitials" HeaderText="UserInitials" SortExpression="UserInitials" /> <asp:BoundField DataField="GroupName" HeaderText="GroupName" SortExpression="GroupName" /> <asp:TemplateField HeaderText="StartDate/StartTime" SortExpression="StartDate"> <EditItemTemplate> <asp:TextBox ID="txtgvStartDate" runat="server" Text='<%# Bind("StartDate") %>' Height="20px" Width="70px"></asp:TextBox> <asp:CalendarExtender ID="txtgvStartDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtgvStartDate"> </asp:CalendarExtender> <asp:DropDownList ID="ddlgvStartTime" runat="server" Text='<%# Bind("StartTime") %>'> <asp:ListItem Value="12:00AM">12:00AM</asp:ListItem> <asp:ListItem Value="1:00AM">1:00AM</asp:ListItem> <asp:ListItem Value="2:00AM">2:00AM</asp:ListItem> <asp:ListItem Value="3:00AM">3:00AM</asp:ListItem> <asp:ListItem Value="4:00AM">4:00AM</asp:ListItem> <asp:ListItem Value="5:00AM">5:00AM</asp:ListItem> <asp:ListItem Value="6:00AM">6:00AM</asp:ListItem> <asp:ListItem Value="7:00AM">7:00AM</asp:ListItem> <asp:ListItem Value="8:00AM">8:00AM</asp:ListItem> <asp:ListItem Value="9:00AM">9:00AM</asp:ListItem> <asp:ListItem Value="10:00AM">10:00AM</asp:ListItem> <asp:ListItem Value="11:00AM">11:00AM</asp:ListItem> <asp:ListItem Value="12:00PM">12:00PM</asp:ListItem> <asp:ListItem Value="1:00PM">1:00PM</asp:ListItem> <asp:ListItem Value="2:00PM">2:00PM</asp:ListItem> <asp:ListItem Value="3:00PM">3:00PM</asp:ListItem> <asp:ListItem Value="4:00PM">4:00PM</asp:ListItem> <asp:ListItem Value="5:00PM">5:00PM</asp:ListItem> <asp:ListItem Value="6:00PM">6:00PM</asp:ListItem> <asp:ListItem Value="7:00PM">7:00PM</asp:ListItem> <asp:ListItem Value="8:00PM">8:00PM</asp:ListItem> <asp:ListItem Value="9:00PM">9:00PM</asp:ListItem> <asp:ListItem Value="10:00PM">10:00PM</asp:ListItem> <asp:ListItem Value="11:00PM">11:00PM</asp:ListItem> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lblgvStartDate" runat="server" Text='<%# Eval("StartDate") %>'></asp:Label> <asp:Label ID="lblgvStartTime" runat="server" Text='<%# Eval("StartTime") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="EndDate/EndTime" SortExpression="EndDate"> <EditItemTemplate> <asp:TextBox ID="txtgvEndDate" runat="server" Text='<%# Bind("EndDate") %>' Height="20px" Width="70px"></asp:TextBox> <asp:CalendarExtender ID="txtgvEndDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtgvEndDate"> </asp:CalendarExtender> <asp:DropDownList ID="ddlgvEndTime" runat="server" SelectedValue='<%# Bind("EndTime") %>'> <asp:ListItem Value="12:00AM">12:00AM</asp:ListItem> <asp:ListItem Value="1:00AM">1:00AM</asp:ListItem> <asp:ListItem Value="2:00AM">2:00AM</asp:ListItem> <asp:ListItem Value="3:00AM">3:00AM</asp:ListItem> <asp:ListItem Value="4:00AM">4:00AM</asp:ListItem> <asp:ListItem Value="5:00AM">5:00AM</asp:ListItem> <asp:ListItem Value="6:00AM">6:00AM</asp:ListItem> <asp:ListItem Value="7:00AM">7:00AM</asp:ListItem> <asp:ListItem Value="8:00AM">8:00AM</asp:ListItem> <asp:ListItem Value="9:00AM">9:00AM</asp:ListItem> <asp:ListItem Value="10:00AM">10:00AM</asp:ListItem> <asp:ListItem Value="11:00AM">11:00AM</asp:ListItem> <asp:ListItem Value="12:00PM">12:00PM</asp:ListItem> <asp:ListItem Value="1:00PM">1:00PM</asp:ListItem> <asp:ListItem Value="2:00PM">2:00PM</asp:ListItem> <asp:ListItem Value="3:00PM">3:00PM</asp:ListItem> <asp:ListItem Value="4:00PM">4:00PM</asp:ListItem> <asp:ListItem Value="5:00PM">5:00PM</asp:ListItem> <asp:ListItem Value="6:00PM">6:00PM</asp:ListItem> <asp:ListItem Value="7:00PM">7:00PM</asp:ListItem> <asp:ListItem Value="8:00PM">8:00PM</asp:ListItem> <asp:ListItem Value="9:00PM">9:00PM</asp:ListItem> <asp:ListItem Value="10:00PM">10:00PM</asp:ListItem> <asp:ListItem Value="11:00PM">11:00PM</asp:ListItem> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lblgvEndDate" runat="server" Text='<%# Eval("EndDate") %>'></asp:Label> <asp:Label ID="lblgvEndTime" runat="server" Text='<%# Eval("EndTime") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="UserComments" HeaderText="UserComments" SortExpression="UserComments" /> <asp:TemplateField HeaderText="RoomName" SortExpression="IntRoom"> <ItemTemplate> <asp:Label ID="lblRoom" runat="server" Text='<%#Eval("IntRoom") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddlgvRoom" runat="server"> </asp:DropDownList> <asp:CascadingDropDown ID="ddlgvRoom_CascadingDropDown" runat="server" Category="Jack" TargetControlID="ddlgvRoom" ServiceMethod="GetRooms" ServicePath="cascadingddl.asmx" LoadingText="[Loading Rooms...]" PromptText="Please Select Room"> </asp:CascadingDropDown> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="JackNumber" SortExpression="IntJack"> <ItemTemplate> <asp:Label ID="lblJack" runat="server" Text='<%#Eval("IntJack") %>'> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddlgvJack" runat="server"> </asp:DropDownList><br /> <asp:CascadingDropDown ID="ddlgvJack_CascadingDropDown" runat="server" Category="Jack" TargetControlID="ddlgvJack" ParentControlID="ddlgvRoom" PromptText="Please Select A Jack" LoadingText="[Loading Jacks...]" ServicePath="cascadingddl.asmx" ServiceMethod="GetJacks"> </asp:CascadingDropDown> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="InternetType" SortExpression="VlanID"> <ItemTemplate> <asp:Label ID="lblgvVlan" runat="server" Text='<%# Eval("VlanID") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddlgvVlan" runat="server" DataSourceID="sourceVlan1" DataTextField="InternetType" DataValueField="VlanID"> </asp:DropDownList> </EditItemTemplate> </asp:TemplateField> <asp:CommandField ShowEditButton="True" /> </Columns> </asp:GridView> <asp:ObjectDataSource ID="sourceGroups" runat="server" DataObjectTypeName="DatabaseComponent.GroupDetails" InsertMethod="InsertGroup" OldValuesParameterFormatString="original_{0}" SelectMethod="GetGroups" TypeName="DatabaseComponent.GroupDB" UpdateMethod="UpdateEmployee"> </asp:ObjectDataSource> <asp:ObjectDataSource ID="sourceVlan1" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetVlans" TypeName="dsVlansTableAdapters.GetVlansTableAdapter"></asp:ObjectDataSource> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html> //C# protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit) { DropDownList dl = (DropDownList)e.Row.FindControl("ddlgvRoom"); } } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { DropDownList ddlgvRoom = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlgvRoom"); string strgvRoom = ddlgvRoom.SelectedItem.Text.ToString(); DropDownList ddlgvJack = (DropDownList) GridView1.Rows[e.RowIndex].FindControl("ddlgvJack"); string strgvJack = ddlgvJack.SelectedItem.Text.ToString(); DropDownList ddlgvVlan = (DropDownList) GridView1.Rows[e.RowIndex].FindControl("ddlgvVlan"); string strgvVlan = ddlgvVlan.SelectedItem.Text.ToString(); }
Regards
Dominic
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful- Proposed as answer by Dominic Abraham Friday, September 23, 2011 3:56 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:58 AM
Tuesday, September 20, 2011 9:11 AM -
Thanks Dominic
Thank You for all your help I really appreciate you taking the time to help me save some of my black hairs from turning grey. I am looking over the code you provided for me and will let you know the outcome.
One thing that I did do was take off the updatepanel as my edit button would not fire when it was within the update panel. As of right now with both of your rowupdating and rowdatabound code it was still producing the same error. So I am assuming I need to add some code to the row_editing event which I am going to give this a try see if I cant figure it out from here.Again thanks for all your help hopefully one day I can return the favor to someone else
Tuesday, September 20, 2011 6:10 PM -
Hi
I tried my code here. When i clicked on edit in the grid view , it comes in the edit mode without any error [I thought initially you got the error while clicking on edit button]. Is that solved ? I didn't try to move further. If i get more free time, i will look in to this again. Anyway update me the status.
Regards
Dominic
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful- Proposed as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:58 AM
Wednesday, September 21, 2011 4:11 AM -
Yes that is my issue however when I use your code if I try to click the edit button on the gridview nothing happens just sits there. Not sure what you have different than I have but I looked at what you posted over and over and cant find anything different.
When I comment out the update panel edit button fires but goes back to the same error of the values not existing. I cant figure out why when i click edit the gridview does not go into edit mode.
Am I missing something?
Wednesday, September 21, 2011 12:42 PM -
Hi
When i clicked on edit, i didn't get any error. I could successfully edit the values. When i clicked on update button, i could successfully read the edited values from code behind. I didn't try to update to db. You do one thing. Keep a copy of your existing code and replace the your entire code with my modified code [both html side and code behind] and try. I made different changes in your code.
For eg:
<asp:DropDownList ID="ddlgvJack" runat="server" DataTextField="JackNumber" DataValueField="intJack" Text='<%# Bind("IntJack") %>' > <asp:ListItem></asp:ListItem> </asp:DropDownList>
To<asp:DropDownList ID="ddlgvJack" runat="server"> </asp:DropDownList><br />
RegardsDominic
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful- Proposed as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:58 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:58 AM
Thursday, September 22, 2011 3:32 PM -
Yes that worked You are a genius. Should have did that a long time ago guess being frustrated makes you overlook simple troubleshooting.
Last question I noticed that when I click edit it does not retain the value that the record has is that because of the way my webservice is coded? Or do I have to tell the findcontrol to keep the values?
Thanks
Thursday, September 22, 2011 6:21 PM -
Hi JayJ24,
Welcome to the MSDN forum!You are more likely to get more efficient responses to ASP.NET issues at http://forums.asp.net where you can contact ASP.NET experts.
Thank you for your understanding and have a nice day,
Yoyo.
Yoyo Jiang[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:58 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, October 28, 2011 7:58 AM
Tuesday, September 27, 2011 2:56 PM -
hi there
same problem
it is gonna make me crazy
no solution, even Microsoft expert
just may it helps you:
http://www.codeproject.com/KB/aspnet/DataBoundDropDownList.aspx
I still lookin' for a solution
Wednesday, January 25, 2012 2:32 AM