Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

how to edit dropdown list in listview control of visual webpart

$
0
0

I am using asp.net ListView control in a visual webpart.When I click on "edit" in the ListView, the values in the dropdown list(which is hard coded), loose their selected index. The findcontrol method, returns null, i.e. for e.x. ((DropdownList)newItem.FindControl("ddlPriority")).SelectedValue returns null as it is unable to find the dropdownlist.
How do I keep the selected value in the dropdown list unchanged when I click on Edit?

My aspx declaration and code behing are as follows.

<ItemTemplate><tr><td><asp:Label  ID="ID" runat="server"><%#Eval("ID") %></asp:Label></td><td><asp:Label runat="server" ID="lblName"><%#Eval("Title") %></asp:Label></td><td><asp:Label runat="server" ID="lblPriority"><%#Eval("Priority") %></asp:Label></td><td><asp:Label runat="server" ID="lblStatus"><%#Eval("Status") %></asp:Label></td><td><asp:LinkButton ID="lnkEdit" runat="server" Text="Edit" CommandName="Edit" /><span onclick="return confirm('Are you sure to delete?')"><asp:LinkButton ID="lnkDelete" runat="server" Text="Delete" CommandName="Delete" ForeColor="Brown"/></span></td></tr></ItemTemplate><EditItemTemplate><tr><td></td><td><asp:TextBox ID="txtName" Width="100" runat="server" Text='<%# Eval("Title") %>' /></td><td><asp:DropDownList ID="ddlPriority" Width="100"  runat="server"><asp:ListItem Value="(1) High">(1) High</asp:ListItem><asp:ListItem Value="(2) Normal">(2) Normal</asp:ListItem><asp:ListItem Value="(3) Low">(3) Low</asp:ListItem></asp:DropDownList></td><td><asp:DropDownList ID="ddlStatus" Width="100"  runat="server" ><asp:ListItem Value="Not Started">Not Started</asp:ListItem><asp:ListItem Value="In Progress">In Progress</asp:ListItem><asp:ListItem Value="Completed">Completed</asp:ListItem></asp:DropDownList></td><td><asp:LinkButton ID="btnUpdate" runat="server" CommandName="Update">Update</asp:LinkButton><asp:LinkButton ID="btnCancel" runat="server" CommandName="Cancel">Cancel</asp:LinkButton></td></tr></EditItemTemplate>

code behind is

protected void EditListViewItem(object sender, ListViewEditEventArgs e)
        {
            try
            {
                ListViewAssgn.EditIndex = e.NewEditIndex;
                SPSite site = SPContext.Current.Site;

                using (SPWeb web = site.OpenWeb())
                {
                    SPList tasklst = web.Lists.TryGetList("Assigned Tasks");
                    if (tasklst != null)
                    {
                        ListViewAssgn.DataSource = tasklst.Items.GetDataTable();
                        DropDownList ddlListPriority = (DropDownList)ListViewAssgn.EditItem.FindControl("ddlPriority");//Error here
                        //ddlListPriority.DataTextField = "Priority";
                        //ddlListPriority.DataValueField = "Priority";
                        ListViewAssgn.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

How do I keep the selected value in the dropdown list unchanged when I click on Edit?

Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>