Hi guys,
I have a problem here. How can i create a dynamic row in gridview the row will defend from the user input.
for example the user enter a 4 then the gridview will generate 4 rows.
Please site me an example.
Thanks,
i havent tried that but gridview is supposed to have a datasource... so you have to insert first the record in the datasource then you rebind the gridview to show the new rows. That means this depends on what dataadapter/datasource you will be using.Hmmm..
For example,
if you were using sqldatasource control you should call sqldatasource1.Insert
if you want it to add X rows then create a loop
for i=1 to X
sqldatasource1.Insert()
next i
After that update the gridview ..
GridView1.Databind
So it really depends on your database and your dataAdapter.. basically this should work.
I don't think you can unless there's a valid data source to populate rows of the grid view. Maybe you could set the values as String.Empty
sino pa ba may ibang sagot dito? this is exactly what I need. I've seen lots of web/form apps that have this "dynamic row". Is looping the right way to do this?
I'm assuming this is an ASP.NET GridView:First, set your gridview's AutoGenerateColumns to false (not really necessary)Next, create your field item and populate it:
BoundField boundField = new BoundField();boundField.HeaderText = "This is the column header";boundField.DataField = "BoundName"; // This is the name to look at how to bind it to data (using INamingContainer)boundField.SortExpression = columnInfo.Name;// boundField.DataFormatString = "Format"; // If your data needs some formating, put it here//boundField.ItemStyle.Width = Unit.Percentage(10); // How wide your column is...// Add the column to your GridViewgridView1.Columns.Add(boundField);There are many field items you can choose from:AutoGeneratedFieldCheckBoxFieldButtonFieldCommandFieldHyperLinkFieldImageFieldTemplateField (using ITemplate)Cheers,-chris
Opps sorry, dynamic rows pala....Just use an extendable collection, like List<YourType> -- populate it on the fly, then bind that data to GridView. Rebind it if necessary.List<string> names = new List<string>();names.Add("Puppy");names.Add("Mickey");names.Add("Goofey");names.Add("Foo");gridView1.DataSource = names;gridView1.DataBind();// If you changed the content of names, just rebind it:gridView1.DataSource = names;gridView1.DataBind();Cheers,-chris
Hi,
I created a sample application to show how to solve this problem.
http://devpinoy.org/blogs/keithrull/archive/2008/07/28/how-to-create-dynamic-input-rows-in-a-gridview-with-asp-net.aspx
Keith