Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

I am using DropDownList in Edit Mode of ListView. All other columns are updated, but dropdowns selected item is not updating, listview is passing old values to store procedure although i am forcefully passing new values of dropdown to store procedure. So how to pass new values to database.

This is my List View

Image of Item Template is here
http://www.freeimagehosting.net/bc3hm

This is ItemTemplate of List View

ASP.NET
<ItemTemplate>
<tr >
       <td>
            <asp:Label ID="CountryCodeLabel" runat="server" Text='<%# Eval("CountryCode") %>'></asp:Label>
      </td>
      <td >
            <asp:Label ID="CountryNameLabel" runat="server" Text='<%# Eval("CountryName") %>'></asp:Label>
     </td>
     <td>
         <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
    </td>
     <td>
      <asp:ImageButton runat=server ID=NameEdit ImageUrl="~/Image/edit.png" Width=20px CommandName="Edit" /> &nbsp                   <asp:ImageButton runat=server ID="NameDelete" CommandName="Delete" ImageUrl="~/Image/delete.png" Width=20px />
    </td>
  </tr>
</ItemTemplate>




This is Edit Mode
Image For Edit is Here
http://www.freeimagehosting.net/8cxrt</a>

And my Edit Template is
ASP.NET
<EditItemTemplate>
<tr>
<td>
<asp:TextBox ID="CodeTextBox" runat="server" Text='<%# Bind("CountryCode") %>' ></asp:TextBox>
 </td>
<td >
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("CountryName") %>' ></asp:TextBox>
 </td>
<td>
<asp:DropDownList ID="NameDropDownList" runat="server" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="NameId" >
</asp:DropDownList>
</td>
<td>
<asp:ImageButton runat=server ID=UpdateSave ImageUrl="~/Image/save.png" Width=20px CommandName="Update" /> &nbsp <asp:ImageButton runat=server ID="UpdateCancel" CommandName="Cancel" ImageUrl="~/Image/undo.png" Width=20px />
</td>
</tr>
</EditItemTemplate>


and For Updating i am handling this event

C#
protected void ListView_ItemUpdating(object sender, ListViewUpdateEventArgs e)

       {

           DropDownList NameDropDownList = (DropDownList)((ListView)sender).Items[e.ItemIndex].FindControl("NameDropDownList ");

                   if (NameDropDownList!= null)

                   {

                       SqlDataSource1.UpdateParameters["NameId"].DefaultValue = NameDropDownList.SelectedValue;

                   }

}


So please help me how to solve that problem.

Thanks In Advance.
Posted
Updated 28-May-12 22:52pm
v2

1 solution

i thing when ever your clicking update button the page is refreshing at that time the dropdownlist values are changing

try like this

protected void ListView_ItemUpdating(object sender, ListViewUpdateEventArgs e)

{

DropDownList NameDropDownList = (DropDownList)((ListView)sender).Items[e.ItemIndex].FindControl("NameDropDownList ");

if (NameDropDownList!= null)

{
if(!IsPostBack )
{
SqlDataSource1.UpdateParameters["NameId"].DefaultValue = NameDropDownList.SelectedValue;
}
}

}
 
Share this answer
 
Comments
vikas.pawar143 29-May-12 5:51am    
No Its not going in If Loop
vikas.pawar143 29-May-12 6:11am    
In quick Watch i have observed that all other parameters default values are null. But in drop down list its not null, actually this value is supplied by me. but its not reflecting in database

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900