I have two dropdownlists 'PakPeriod' and 'PackageName' in update form, 'Pack period' binding in '.axpx' page only, but 'PackName' binding in 'PackPeriod_SelectedIndexChange' event from database.
problem: when I clicking 'packperiod' then page getting post back, I have to avoid this post back and should work 'PackPeriod_SelectedIndexChange' (for bind 'PackageName' dropdown list and other jobs) and update form on 'update' button click,
I used update panel also but its not working , so what is the solution ?
/*packPeriod Bind*/
/*Pckname bindind*/
public void ddlUpdatepackNameBind()
{
string period = ddlPackPeriodEdit.SelectedValue;
try
{
//open the db connection if it is closed...
if (connection.State == ConnectionState.Closed)
connection.Open();
string packagePeriod = ddlPackPeriodEdit.SelectedValue;
switch (period)
{
case "Monthly":
command = new SqlCommand();
command.CommandText = "sp_Get_PackName";
command.CommandType = CommandType.StoredProcedure;
command.Connection = connection;
command.Parameters.AddWithValue("@packagePeriod", packagePeriod);
ddlPackNameEdit.DataSource = command.ExecuteReader();
ddlPackNameEdit.DataTextField = "PackageName";
ddlPackNameEdit.DataValueField = "PackageId";
ddlPackNameEdit.DataBind();
ddlPackNameEdit.Items.Insert(0, new ListItem("--Select Package Name--", "0"));
break;
case "Quarterly":
command = new SqlCommand();
command.CommandText = "sp_Get_PackName";
command.CommandType = CommandType.StoredProcedure;
command.Connection = connection;
command.Parameters.AddWithValue("@packagePeriod", packagePeriod);
ddlPackNameEdit.DataSource = command.ExecuteReader();
ddlPackNameEdit.DataTextField = "PackageName";
ddlPackNameEdit.DataValueField = "PackageId";
ddlPackNameEdit.DataBind();
ddlPackNameEdit.Items.Insert(0, new ListItem("--Select Package Name--", "0"));
break;
case "HalfYearly":
command = new SqlCommand();
command.CommandText = "sp_Get_PackName";
command.CommandType = CommandType.StoredProcedure;
command.Connection = connection;
command.Parameters.AddWithValue("@packagePeriod", packagePeriod);
ddlPackNameEdit.DataSource = command.ExecuteReader();
ddlPackNameEdit.DataTextField = "PackageName";
ddlPackNameEdit.DataValueField = "PackageId";
ddlPackNameEdit.DataBind();
ddlPackNameEdit.Items.Insert(0, new ListItem("--Select Package Name--", "0"));
break;
case "Yearly":
command = new SqlCommand();
command.CommandText = "sp_Get_PackName";
command.CommandType = CommandType.StoredProcedure;
command.Connection = connection;
command.Parameters.AddWithValue("@packagePeriod", packagePeriod);
ddlPackNameEdit.DataSource = command.ExecuteReader();
ddlPackNameEdit.DataTextField = "PackageName";
ddlPackNameEdit.DataValueField = "PackageId";
ddlPackNameEdit.DataBind();
ddlPackNameEdit.Items.Insert(0, new ListItem("--Select Package Name--", "0"));
break;
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally //Close db Connection if it is open....
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
}
/*updating form*/
public void packUpdate()
{
try
{
//open the db connection if it is closed...
if (connection.State == ConnectionState.Closed)
connection.Open();
int packageId = Convert.ToInt32(ddlPackNameEdit.SelectedValue);
string packNewName = txtPackNameEdit.Text;
string packNewPeriod = ddlPackPeriodEdit.SelectedItem.ToString();
string packNewPrice = txtPackPriceEdit.Text;
command = new SqlCommand();
command.CommandText = "sp_PackageUpdate";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@packageId", packageId);
command.Parameters.AddWithValue("@packNewName", packNewName);
command.Parameters.AddWithValue("@packNewPeriod", packNewPeriod);
command.Parameters.AddWithValue("@packNewPrice", packNewPrice);
command.Connection = connection;
command.ExecuteNonQuery();
lblMessage.Text = "Record Updated successfully";
lblMessage.Visible = true;
ddlPackNameEdit.SelectedIndex = -1;
ddlPackPeriodEdit.SelectedIndex = -1;
txtPackNameEdit.Text = "";
txtPackPriceEdit.Text = "";
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally //Close db Connection if it is open....
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
}
/*Update form*/
protected void btnPackageUpdate_Click(object sender, EventArgs e)
{
packUpdate();
}


Azaad Abbas127 reputationPosted Mar 20, 2015, 2:44 AM EDT
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Country_state_city._Default" %>
ForeColor="Red" Width="100px">
AppendDataBoundItems="true" runat="server" Height="20px" Width="156px"
onselectedindexchanged="ddlcountry_SelectedIndexChanged" Font-Bold="True"
ForeColor="#FF9900">
ForeColor="Red" Width="100px">
AppendDataBoundItems ="true" runat="server" Height="20px"
Width="155px" onselectedindexchanged="ddlstate_SelectedIndexChanged" Font-Bold="True"
ForeColor="#993300">
ForeColor="Red" Width="100px">
runat="server" Height="20px" Width="155px" Font-Bold="True" ForeColor="#CCCC00">
Keertti Raj Thangavelu BabuRank #3,979 · 374 reputationPosted Mar 20, 2015, 12:43 AM EDT
use this code in page load.
private void Page_Load()
{
if (!IsPostBack)
{
// use this space for function that should not Postback.
}
}
Dawood AbbasRank #6,413 · 267 reputationPosted Mar 20, 2015, 1:32 AM EDT
so iam tried like below but after bind 'packname' one moe extra dropdown with label displaying.
Dawood AbbasRank #6,413 · 267 reputationPosted Mar 20, 2015, 2:47 AM EDT
now I got that have to attach with every control.
many many thanx.