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();
}
4 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Azaad AbbasPosted Mar 20, 2015, 6:44 AM
<%@ 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">
Dawood AbbasPosted Mar 20, 2015, 6:47 AM
now I got that have to attach with every control.
many many thanx.
Dawood AbbasPosted Mar 20, 2015, 5:32 AM
so iam tried like below but after bind 'packname' one moe extra dropdown with label displaying.
Keertti Raj Thangavelu BabuPosted Mar 20, 2015, 4:43 AM
use this code in page load.
private void Page_Load()
{
if (!IsPostBack)
{
// use this space for function that should not Postback.
}
}