Home > DeveloperSection > Forums > How can I Find Gridview in a listview using C#?
Simons Hood
Simons Hood

Total Post:70

Points:494
Posted on    October-22-2013 3:46 AM

 C# C# 
Ratings:


 1 Reply(s)
 1318  View(s)
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.!!!



Royce Roy
Royce Roy

Total Post:134

Points:938
Posted on    October-22-2013 4:04 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick