I want to add a textBox in GridView knowing that the textbox retrieves data from a collection like ArrayList or List(OF ..) not from a dataSource (ASP.net)
Asked
Active
Viewed 1,689 times
1 Answers
0
Set the DataSource in code:
// in this case the object I am using is:
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
public bool IsInStock { get; set; }
}
private void BindGrid()
{
// in the GetProducts() method return the collection
List<Product> r = GetProducts();
this.grdSomething.DataSource = r;
this.grdSomething.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
this.BindGrid();
}
protected void grdSomething_EditCommand(object sender, DataGridCommandEventArgs e)
{
this.grdSomething.EditItemIndex = e.Item.ItemIndex;
this.BindGrid();
}
Simply add a bound field column like this:
<asp:DataGrid runat="server" ID="grdSomething" AutoGenerateColumns="False"
OnEditCommand="grdSomething_EditCommand">
<Columns>
<asp:BoundColumn DataField="Name"></asp:BoundColumn>
<asp:EditCommandColumn EditText="Edit"></asp:EditCommandColumn>
</Columns>
</asp:DataGrid>
That's it

Jupaol
- 21,107
- 8
- 68
- 100
-
but how i can bound it with data from collection like ArrayList or List(OF ..) – Yassine edouiri Jun 14 '12 at 23:49
-
Oh to bind it you just have to specify the name of the field, gimme a sec I will update the post – Jupaol Jun 14 '12 at 23:53
-
tnksss dudde ... but unfortunately i found it difficult to understand ..can you be more specific tnksssssssss – Yassine edouiri Jun 14 '12 at 23:59
-
You can return an Array instead, it's equivalent lemme update it. `List<>` implements `IEnumerable<>` – Jupaol Jun 15 '12 at 00:03
-
tnkks agian ^^ but i want to add the data of an collecion .. of course just one attribute .. in a textbox only not the hole gridview – Yassine edouiri Jun 15 '12 at 00:06