Click here to Skip to main content
14,391,319 members
Rate this:
Please Sign up or sign in to vote.
See more:
In run mode as follows
Link(Headertext) Availabledate(Headertext)

Link button 27 may 2015
Link button 29 jun 2015
Link button 25 jul 2015
Link button
Link button 29 may 2015
Link button 26 jun 2015
Link button 24 jul 2015
Link button

i dont want to show Link button when gridview row is empty.
because 4throw and 8throw is empty.

for that how can i do in c#.
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 2

//please use cell formatting event and remove un necessary row.

private void grdview1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            try
            {
                if (this.grdview1.Columns[e.ColumnIndex].Name == "Availabledate")
                {
                    if (this.grdview1.Rows[e.RowIndex] != null)
                    {
                        if (string.IsNullOrEmpty(this.grdview1["Availabledate", e.RowIndex].Value.ToString()) )
                        {
                            this.grdview1.Rows.RemoveAt(e.RowIndex);
                        }
                    }
                }
            }
            catch(Exception ex)
            {
            }
}
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

You should use RowDatabound event and check if the row(linkbutton value) is empty then set visible false to your linkbutton.

example:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnk= e.Row.FindControl("yourlinkbuttonID") as LinkButton;
            //assuming the text9 27 may 2015) is written on link button
            if (lnk.Text == "")
            {
                lnk.Visible = false;
            }
        }
    }
   
v3
Rate this:
Please Sign up or sign in to vote.

Solution 3

private void grdview1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            try
            {
                if (this.grdview1.Columns[e.ColumnIndex].Name == "Availabledate")
                {
                    if (this.grdview1.Rows[e.RowIndex] != null)
                    {
                        if (string.IsNullOrEmpty(this.grdview1["Availabledate", e.RowIndex].Value.ToString()) )
                        {
                            this.grdview1.Rows.RemoveAt(e.RowIndex);
                        }
                    }
                }
            }
            catch(Exception ex)
            {
            }
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100