Hi JennyD6856,
Please refer below sample.
You have given wrong id of DropDownList, Id of DropDownList is DropDownList1 but you had given ddlstatus.
HTML
<asp:ListView ID="ListViewOrderProductDetails" runat="server" DataKeyNames="CustomerId">
<LayoutTemplate>
<table border="1" class="footable table table-stripped toggle-arrow-tiny" data-page-size="10">
<thead>
<tr>
<th data-toggle="true">
CustomerID
</th>
<th data-hide="phone">
Name
</th>
<th data-hide="phone">
Status
</th>
</tr>
</thead>
<tbody>
<tr id="itemPlaceHolder" runat="server">
</tr>
</tbody>
<tr>
<td colspan="3">
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListViewOrderProductDetails"
PageSize="50">
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" ShowPreviousPageButton="true"
ShowNextPageButton="false" />
<asp:NumericPagerField ButtonType="Link" />
<asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="true" ShowLastPageButton="false"
ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%#Eval("CustomerId") %>
</td>
<td>
<%#Eval("Name") %>
</td>
<td>
<asp:HiddenField ID="hdId" runat="server" Value='<%# Eval("CustomerId") %>' />
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
DataTextField="CountryName" DataValueField="CountryId" Width="263px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:constr %>"
SelectCommand="SELECT CountryId,CountryName FROM [Country]"></asp:SqlDataSource>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:Button ID="btnupdate" runat="server" Text='Update' CommandName="Update" class="btn btn-primary btn-sm"
OnClick="btnupdate_Click" />
Namespaces
C#
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
ListViewOrderProductDetails.DataSource = dt;
ListViewOrderProductDetails.DataBind();
}
}
protected void btnupdate_Click(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
string strQry = string.Empty;
foreach (ListViewItem item in ListViewOrderProductDetails.Items)
{
HiddenField hdId = (HiddenField)item.FindControl("hdId");
DropDownList orderstatus = (DropDownList)item.FindControl("DropDownList1");
if (orderstatus.SelectedValue != null)
{
con.Open();
strQry = "update Country set CountryName='" + orderstatus.SelectedItem.Text + "' from Country where CountryId =" + hdId.Value.ToString().Trim();
SqlCommand cmd = new SqlCommand(strQry, con);
cmd.ExecuteNonQuery();
con.Close();
}
}
}