add columns in gridview at runtime
-
I m adding columns in gridview at runtime ,but these get lost at postbask,I have to reload all at postback ,how should i add columns that it donot disappear at postback.
Are you binding to your data source in postback ? If you are, you'll lose your columns. If not, I'd have thought not.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Are you binding to your data source in postback ? If you are, you'll lose your columns. If not, I'd have thought not.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
if i do like if(!ispostback) { gridview.datasource=datasource; } all the columns disappear,I have to reload/bind with datasource at postback. I m adding columns in grid like this private void AddColumns() { TemplateField bfield = new TemplateField(); try { HeaderText = GetGlobalResourceObject("ViewQuotations", col.ColumnName).ToString(); //Assigns the name of the column in the lable. } catch (Exception e) { HeaderText = col.ColumnName; } //Initalize the DataField value. bfield.HeaderTemplate = new GridViewTemplate(ListItemType.Header, col.ColumnName, HeaderText); //Initialize the HeaderText field value. bfield.ItemTemplate = new GridViewTemplate(ListItemType.Item, col.ColumnName); //Add the newly created bound field to the GridView. grdViewEqpCard.Columns.Add(bfield); }
-
I m adding columns in gridview at runtime ,but these get lost at postbask,I have to reload all at postback ,how should i add columns that it donot disappear at postback.
-
Your datasource should be dynamic. Make your datasourse (datatable, dataset) at runtime and bind it to the grid (grid should've it's property AutoGeneratedColumns to True)
Please don't forget to mark 'Good Answer', if you find it really a good one! Kashif
-
I need to add some links and radiobuttons in gridview columns at gridview row bound event ,that 's the reason i myself adding fields in gridview,not setting its autogenerate columns ot true
-
You can still add link through rowdatabound event.
Please don't forget to mark 'Good Answer', if you find it really a good one! Kashif
-
in rowdatabound create an object of radiobutton and add it to the column you want.
Please don't forget to mark 'Good Answer', if you find it really a good one! Kashif