ASP.NET - Null when executing ? - Asked By Jahir on 28-Feb-12 02:46 AM


foreach (GridViewRow row in GridView1.Rows)

{


DropDownList drpregion = (DropDownList)row.FindControl("dropregion");

DropDownList drpdown1 = (DropDownList)row.FindControl("dropstate");

DropDownList dpdown1 = (DropDownList)row.FindControl("dropcity");

if (drpdown1 != null)

{

adap =

new SqlDataAdapter("select * from tbl_statemaster where regionid='" +drpregion.SelectedItem.Value+ "'", con);

ds = new DataSet();

adap.Fill(ds);

drpdown1.DataTextField =

"statename";

drpdown1.DataValueField = "stateid";

drpdown1.DataSource = ds;

drpdown1.DataBind();


//this.drpdown1.Items.Insert(00, "Select");

//drpdown1.SelectedIndex = 0;

}


if (dpdown1 != null)

{

adap =

new SqlDataAdapter("select * from tbl_citymaster where stateid='" +drpdown1.SelectedItem.Value+ "'", con);

ds = new DataSet();

adap.Fill(ds);

dpdown1.DataTextField =

"cityname";

dpdown1.DataValueField = "cityid";

dpdown1.DataSource = ds;

dpdown1.DataBind();


//this.dpdown1.Items.Insert(00, "Select");

//dpdown1.SelectedIndex = 0;

}

}

D Company replied to Jahir on 28-Feb-12 03:23 AM
Where u are getting null value,

follow this Egghead thread , it has good posts related to finding controls inside the grid. and also request you to post your problem correctly, with complete description and points

Hope this helps
Regards
D

Somesh Yadav replied to Jahir on 28-Feb-12 03:39 AM

This is how you check if the column's value is null

if (table.Rows.Count > 0) // if table is not empty
{
       
if (Convert.IsDBNull(table.Rows[0]["columnName"])) // It's checking null value for columnName 'columnName' of first row
       
{
                   
//This column's value is null
       
}
       
else
       
{
                   
//column has value other than null
       
}
}