if (row.Cells[2].Text.ToString() == " ")
            {
                txtstreet.Text = string.Empty;
            }

Help me out pls. I want to check row.cell[2].Text for null

In my suggestion, you can put label to cell and fill, then check label is empty or not.

Member Avatar for stbuchok

Why can't you do the following?

if (row.Cells[2].Text == null || row.Cells[2].Text.ToString() == " ")
{
    txtstreet.Text = string.Empty;
}

//--- myCell is a Cell object

if (myCell.Value == null && myCell.Formula == "")
{
//--- Cell is empty
}

Member Avatar for stbuchok

windso0, myCell.Formula? Where are you getting this property from?

Thanks dudes for nice suggestion but my problem is still there i have a dropdownlist which is populated from Province table.In GridView SelectedIndexChanging When i select the row then it fill all the texboxes and dropdownlist.Problm is that if in Province field is null then it throws exception.
Exception:
'ddlstate' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value.
On Populating DrodownList i use this approch.
ddlstate.Items.Insert(0, "--Select Province--");
GridView Code SelectedIndexChanging

if (row.Cells[9].Text == null || row.Cells[9].Text.ToString() == " ")
                
            {
                ddlstate.SelectedIndex = -1;
            }
            else
            {
                ddlstate.SelectedValue = row.Cells[9].Text;
            }
Member Avatar for stbuchok

The value property and the text property are 2 different things. Are you sure you don't need to actually get the Text and not the Value?

ddlstate.Items.FindByText(row.Cells[9].Text).Selected;

Dude that line of code gives error
ddlstate.Items.FindByText(row.Cells[9].Text).Selected;
Error 1 Only assignment, call, increment, decrement, and new object expressions can be used as a statement.

Member Avatar for stbuchok

Sorry, I forgot to complete your code. You realize that Intellesnse tells you what are properties and what are methods in the list that comes up right?

ddlstate.Items.FindByText(row.Cells[9].Text).Selected = true;

Thank You.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.