Problem to Gridview row and label

Hi,
As there can be empty value to the list item of DDL, how to avoid the display of "&nbsp" below?
https://dl.dropboxusercontent.com/u/40211031/tt96.png

Can I have details to have the Labels as shown in 1st 2 rows below
https://dl.dropboxusercontent.com/u/40211031/tt97.png

within Gridview?
LVL 11
HuaMin ChenSystem AnalystAsked:
Who is Participating?
 
Lokesh B RDeveloperCommented:
Hi,

Nope this method and ASPX code of Dropdownlist.

this.BindDropDown(ddl, selVal);
0
 
Lokesh B RDeveloperCommented:
Hi,

1. It will not show "&nbsp" in DropDownList if there are no Items.

Can you post the DropDownList ASPX & code behind?
0
 
HuaMin ChenSystem AnalystAuthor Commented:
Many thanks.
One record within the Gridview is having empty on that column, while there is no empty value to DDL.

Is this the event you want to see?
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //ds = GetDataSet();
            string selVal;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if ((e.Row.RowState & DataControlRowState.Edit) > 0)
                {
                    DropDownList ddl = (DropDownList)e.Row.FindControl("ddl2");
                    if (ddl == null)
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "InfoB", "javascript:alert('Unable to bind Edit row in Grid.');", true);
                        //lb_msg.Text = "Unable to bind Edit row in Grid.";
                        return;
                    }
                    else
                    {
                        if (e.Row.RowIndex >= 0)
                            selVal = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
                        else
                            selVal = "";
                        this.BindDropDown(ddl, selVal);
                    }

                    Label lb_rt = (Label)e.Row.FindControl("Item_rate");
                    ddl.Enabled = true;
                }
                else
                {
                    DropDownList ddl = (DropDownList)e.Row.FindControl("ddl");
                    if (ddl == null)
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "InfoB", "javascript:alert('Unable to bind row in Grid.');", true);
                        //lb_msg.Text = "Unable to bind row in Grid." + Convert.ToString(e.Row.RowState);
                        return;
                    }
                    else
                    {
                        if (e.Row.RowIndex >= 0)
                            selVal = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
                        else
                            selVal = "";
                        this.BindDropDown(ddl, selVal);
                    }
                    Label lb_rt = (Label)e.Row.FindControl("Item_rate");

                    ddl.Enabled = false;
                }
            }

            if (e.Row.RowType == DataControlRowType.Footer)
            {
                DropDownList ddl = (DropDownList)e.Row.FindControl("ddl3");
                if (ddl == null)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "InfoB", "javascript:alert('Unable to bind footer row in Grid.');", true);
                    //lb_msg.Text = "Unable to bind footer row in Grid.";
                    return;
                }
                else
                {
                    /*if (e.Row.RowIndex >= 0)
                        selVal = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
                    else*/
                        selVal = "";
                    this.BindDropDown(ddl, selVal);
                }
                Label lb_rt = (Label)e.Row.FindControl("Item_rate");

                ddl.Enabled = false;
            }
        }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.