{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
protected void btnSubmitQuery_Click(object sender, EventArgs e)
{
BindGrid();
}
private void BindGrid()
{
{ con = new SqlConnection(ConfigurationManager.ConnectionStrings["CrciketInsighterConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand();
{
cmd.CommandText = "getBattingPlayersOA";
cmd.CommandType = CommandType.StoredProcedure;
int formatId = 0, resultId = 0, venueID = 0, teamID = 0;
#region Add Parameters
if (rdODI.Checked)
formatId = 2;
else if (rdT20.Checked)
formatId = 3;
else if (rdTest.Checked)
formatId = 1;
if (WonCheckBox.Checked) resultId = 1;
else if (LostCheckBox.Checked) resultId = 2;
else if (TiedCheckBox.Checked) resultId = 3;
else resultId = 4;
if (rdhome.Checked) venueID = 1;
else if (rdaway.Checked) venueID = 2;
else if (rdAll.Checked) venueID = 4;
else if (rdneutral.Checked) venueID = 3;
string name = "Pakistan";
// here no value is being assigned to a dropdown list .
if (ddTeam.SelectedItem.Value == name) teamID=6;
cmd.Parameters.AddWithValue("@resultId", resultId);
cmd.Parameters.AddWithValue("@venueId", venueID);
cmd.Parameters.AddWithValue("@genderId", 1);
//Error here team ID is not assigned cmd.Parameters.AddWithValue("@teamId",teamID);
cmd.Parameters.AddWithValue("@formatID", 1);
#endregion
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
grdResult.DataSource = ds;
grdResult.DataBind();
}
}
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
con.Open();
query = "select * from OA_PlayerBat where Team_ID ='" + ddTeam.SelectedItem + "'";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ddTeam.DataSource = ds;
ddTeam.DataBind();
con.Close();
}
catch (Exception ex)
{
Response.Redirect(ex.Message);
}
}
}
}
Issues I am facing:
no value is being set to a drop-down list i have mentioned the lines where the errors are. kindly see if you can help me out in sorting this. Thanks
if (!this.IsPostBack)
{
this.BindGrid();
}
}
protected void btnSubmitQuery_Click(object sender, EventArgs e)
{
BindGrid();
}
private void BindGrid()
{
{ con = new SqlConnection(ConfigurationManager.ConnectionStrings["CrciketInsighterConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand();
{
cmd.CommandText = "getBattingPlayersOA";
cmd.CommandType = CommandType.StoredProcedure;
int formatId = 0, resultId = 0, venueID = 0, teamID = 0;
#region Add Parameters
if (rdODI.Checked)
formatId = 2;
else if (rdT20.Checked)
formatId = 3;
else if (rdTest.Checked)
formatId = 1;
if (WonCheckBox.Checked) resultId = 1;
else if (LostCheckBox.Checked) resultId = 2;
else if (TiedCheckBox.Checked) resultId = 3;
else resultId = 4;
if (rdhome.Checked) venueID = 1;
else if (rdaway.Checked) venueID = 2;
else if (rdAll.Checked) venueID = 4;
else if (rdneutral.Checked) venueID = 3;
string name = "Pakistan";
// here no value is being assigned to a dropdown list .
if (ddTeam.SelectedItem.Value == name) teamID=6;
cmd.Parameters.AddWithValue("@resultId", resultId);
cmd.Parameters.AddWithValue("@venueId", venueID);
cmd.Parameters.AddWithValue("@genderId", 1);
//Error here team ID is not assigned cmd.Parameters.AddWithValue("@teamId",teamID);
cmd.Parameters.AddWithValue("@formatID", 1);
#endregion
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
grdResult.DataSource = ds;
grdResult.DataBind();
}
}
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
con.Open();
query = "select * from OA_PlayerBat where Team_ID ='" + ddTeam.SelectedItem + "'";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ddTeam.DataSource = ds;
ddTeam.DataBind();
con.Close();
}
catch (Exception ex)
{
Response.Redirect(ex.Message);
}
}
}
}
Issues I am facing:
no value is being set to a drop-down list i have mentioned the lines where the errors are. kindly see if you can help me out in sorting this. Thanks
shifa AliPosted Jul 20, 2016, 3:02 PM
Rajeev PunhaniPosted Jul 4, 2016, 6:01 AM
Hi Shifa,
Where exactly are you binding ddTeam ? It is a blank dropdown. If it is hardcoded then text should be exact.
shifa AliPosted Jul 4, 2016, 5:42 AM
Rajeev PunhaniPosted Jul 4, 2016, 4:59 AM
Hi Shifa,
Please make a separate method for binding dropdown(DropDownList1) and call it in isnotpostback.This will populate your dropdown.One more thing this method should be called before binding grid.
If the above solution is helpful then,accept the answer.