You must Sign In to post a response.
  • Category: ASP.NET

    Deleting empty rows from gridview at runtym ......pageload

    Hello!!!

    i m having a problem
    i want a code for deleting the empty rows from gridview at run time at pageload

    Code to chek whether row is empty or not , if empty then the row won't be show in gridview...


    Thanking You

    Vinay Kumar
  • #660372


    dv = New DataView(ds.Tables(0))
    GridView1.DataSource = dv
    GridView1.DataBind()
    Dim bIsGridEmpty As Boolean = True
    For j As Integer = 0 To GridView1.Rows.Count - 1
    If GridView1.Rows(j).Cells(0).Text <> String.Empty Then
    bIsGridEmpty = False
    GridView1.DeleteRow(j)
    End If


  • #660376
    thanx for you help rajeshwari but it is not working....

  • #660480
    Try this example

    using System;
    using System.Configuration;
    using System.Data;

    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;

    using System.Xml;
    using System.IO;
    using System.Data.SqlClient;
    public partial class _Default : System.Web.UI.Page
    {



    protected void Page_Load(object sender, EventArgs e)
    {
    DataRow dtrow;
    DataTable dtNewTable;
    dtNewTable = new DataTable();
    DataColumn dtcol, dtcol1;
    dtcol = new DataColumn();
    dtcol1 = new DataColumn();
    dtcol.DataType = System.Type.GetType("System.String");
    dtcol.ColumnName = "Emp ID";
    dtNewTable.Columns.Add(dtcol);
    dtcol1.DataType = System.Type.GetType("System.String");
    dtcol1.ColumnName = "Emp Name";
    dtNewTable.Columns.Add(dtcol1);
    int i;
    for (i = 0; i < 4; i++)
    {


    dtrow = dtNewTable.NewRow();
    dtrow["Emp ID"] = string.Empty;
    dtrow["Emp Name"] = string.Empty;
    dtNewTable.Rows.Add(dtrow);


    }
    if (dtNewTable.Rows.Count > 0)
    {
    int count;
    for (count = 0; count < dtNewTable.Rows.Count;)
    {
    if (dtNewTable.Rows[count]["Emp ID"].ToString() != string.Empty)
    {
    dtNewTable.Rows[count].Delete();
    dtNewTable.AcceptChanges();
    if (count == 0)
    {
    count = 1;
    }
    count = count - 1;

    }
    else
    {
    count = count + 1;
    }
    }
    }
    GridView1.DataSource = dtNewTable;
    GridView1.DataBind();
    }
    }




    Thanks & Regards
    G.Renganathan
    Nothing is mine ,Everything is yours!!!

  • #660483
    thanx G.Renganathan
    thanks u very much


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.