Please take a look at the following pages:-
You can see Two values in comboBox. But only the first value is storing in database. If I choose "37" , the value in databse will be "36". look at the saved data in GridView:-
Why this happening?.
Here I posting the btnSave_Click Event:-
protected void btnSave_Click(object sender, EventArgs e)
{
divisionSP spDiv = new divisionSP();
divisionInfo InfoDiv = new divisionInfo();
InfoDiv.divisionName = txtDivision.Text;
InfoDiv.classId = decimal.Parse(cmbClassName.SelectedValue.ToString());
spDiv.DivisionAdd(InfoDiv);
mvDivision.ActiveViewIndex = 1;
gridFill();
}
Please help me in this topic.

Iftikar HussainPosted Aug 23, 2013, 12:37 PM
Regards,
Iftikar
Bineesh ViswanathPosted Aug 23, 2013, 12:28 PM
I did the save function two times. That's why there are two classId.
I want the classId to be availed in tbl_Division.
My values in tbl_Divisions are:-
The combofill function is:-
1) SQL SP:-
ALTER PROCEDURE classViewAll
AS
SELECT classId,className,noOfSeats FROM tbl_Class
2) classSP.cs:-
public DataTable classViewAll()
{
DataTable d = new DataTable();
SqlDataAdapter a = new SqlDataAdapter("classViewAll", sqlCon);
a.SelectCommand.CommandType = CommandType.StoredProcedure;
a.Fill(d);
return d;
}
3) Division.aspx,cs:-
public void comboFill()
{
SqlDataAdapter a = new SqlDataAdapter("select * from tbl_Class", sqlCon);
DataTable d = new DataTable();
a.Fill(d);
cmbClassName.DataSource = d;
cmbClassName.DataValueField = "classId";
cmbClassName.DataTextField = "className";
cmbClassName.DataBind();
}
Iftikar HussainPosted Aug 23, 2013, 11:26 AM
There are how many values in your combobox? Share me the code for binding the combobox? you need to fill the combo only first time during page load. so in page_load
if(!IsPostBack)
{
fill comobo
}
Regards,
Iftikar