HOW CAN I FIND GRIDVIEW IN A LISTVIEW USING C#?

Simons Hood

Total Post:70

Points:494
Posted by  Simons Hood
C# 
C#
 1704  View(s)
Ratings:
Rate this:

I have a gridview in template field of listview. I got gridview if i use the following line of code

protected void listView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
   if (e.Item.ItemType == ListViewItemType.DataItem)
   {
        ListViewDataItem itemList = (ListViewDataItem)e.Item;
        GridView grdView = (GridView) itemList.FindControl("gridView");
   }
}

I want to make this gridview editable and I don't know how it done please help me out.!!!

  1. Royce Roy

    Post:149

    Points:1043
    Re: How can I Find Gridview in a listview using C#?

    Hey  Samuel!
    Use Below line of code: -

    GridView grdView = (GridView)item.FindControl("gridView");
    DataTable dataTable = new DataTable();
    dt.Columns.Add("Columnname"); 
    DataRow dataRow = dataTable.NewRow();
    dataRow["Columnname"] = "Wellcome";
    dataTable.Rows.Add(dataRow);
    grdView.DataSource = dataTable; 
    grdView.DataBind();

      Modified On Apr-05-2016 03:26:45 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!