Dynamic Datagrid - with dynamic columns

Can anyone help with this issue :

I have created an editable dynamic grid with templates and need to update the columns(ie add more or remove columns) in the grid if certain data changes. I have created the datagrid in Sub page_init, but need to add columns when necessary. I think I basically need to know how to call the onInit event from my page when needed to recreated the grid. The onInit should read the data from the dbase and if the are any changes, it will be reflected on the new grid.
Thanks !
6/13/2004 5:42:32 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

7 Replies

Similar Articles

[PageSpeed] 6

You can always call an implementation of the Init event of the page from other places of the page but doing so after the Load event won't make sense - ViewState would already be loaded. You have to re-create all the additional columns before the Load event is run and i suggest you do it in the same place where you create the grid itself.

Bug [MCSD]
6/14/2004 12:32:25 PM
Thanks for the reply !

I actually discoverd that the grid corrects itself if I bind it when I click a button. I assume that the page_init gets fired and therefore all changes that are in the db are presented correctly in the grid(ie the correct columns are removed or added). I would prefer not to press this button, but rather have changes reflected immediately - and therefore would want to fire a page_init myself rather than have a button doing that job.
So even if the viewstate is loaded surly I could fire an init event and that would just reload everything (from the db) from scratch ?
Just to mention all the columns are in one table and rows in another, I maintain these tables depending on user input - these tables will always represent the grid at any time - I just have to load it into the grid.
Thanks again for your input !
6/14/2004 5:40:41 PM
The only to raise the page_init event is to either request the page from, post the page to itself or use the Response.Redirect from within you code but response.redirect is equivalent of a new page request and Page.IsPostback will be false.

You cannot just magically reset the page and make it start running from scratch from your code and to be honest, i don't see any reason for doing so.
One more thing - what do you mean by ' would prefer not to press this button, but rather have changes reflected immediately...' - pressing a button posts the page to itself which means page is already shown to the user. So how do you envision changes to be immediately reflected - do you mean if someone else changes something then those changes must be reflected on your page? If so, then you need to consider the refresh metatag - it is the only way to make the page refresh periodically and still - this will not be the immediate refresh - http is stateless.

Bug [MCSD]
6/15/2004 10:39:27 AM
Hi Nikolai

This dynamic grid is displayed with two other grids – one for columns and one for rows. As the user alters these tables, so the changes are reflected in the dynamic grid. When rows are altered all is well and good as the columns are fixed and the grid does not have to re-create. The problems is when a column is added or removed, the grid has to re-create – and when I said that I need to call page_init, what I should have said was that I needed to do a postback ( I think! Is the page reloaded from scratch each time a postback occurs ?). Perhaps the refresh metatag that you mentioned is what I need - Although not sure how to implement this.
What I understand is that every time I hit the button, that I mentioned in my last post, what was happening, was that the page was been “posted-back” and therefore all was updated.
Do you know of any good articles that would explain the viewstate and how it is created/maintained?
Thanks again
6/15/2004 6:53:50 PM
Sorry, don't have any links related to viewstate but would not help you much here, i guess.

Now, flow of events in your page became clearer but not completely yet. You should understand that something sounds completely logical to you might not to the others. When you are posting the question try to make sure anyone could fully understand it, try to look at your own question from the point of view of the complete outsider.
Now, I've got only tiny bit to clarify here - you say there are 3 grids - main one, one for columns and one for rows. Further you say - 'As the user alters these tables' - i guess you meant grids. Now, how the user alters those grids. For instance, how the user adds a new column to the dynamic grid? - Does he click some kinda 'Add New' button then defines the details the column then hits the save button? You should understand, knowing the whole process flow would greatly simplify the answer.
Now, Postback is a request send to the server using the POST method, i.e. usually click of a button, LinkButton, ImageButton, change of the DropDownList's selected item (if its postback is enabled etc).
Let me try to propose a solution based on my assumptions:
1. I assume your dynamic grid does not have any sorting/paging enabled
2. I assume that after defining a new column user must hit the update button
3. When the updatebutton is hit, you create a definition of the new column and save it somewhere
4. Now, after this happens, simply user Response.Redirect to send the user to the same page again - a new request (not postback) will be initiated and page_init will fire where you will be able to create all the columns in dynamic grid
Refresh metatag will not help you here but will rather annoy your users
There is also another option - to organize the postback, not a new request, after the column update you could emmit the javascript code into the page every time the columns grid is changed. That javascript would post the page to itself and grid would be updated
As you can see, there are few options. If none fits you - explain your process flow fully, to the detail and we'll see.
Bug [MCSD]
6/16/2004 7:48:05 AM
Your assumptions are indeed correct and so is your answer!

I simply added the Response.Redirect and that sufficed.
Just for clarity, when a page postback occurs are only events like button clicks and DropdownList selected items processed and page events not fired?
Thank you for the help
6/16/2004 7:40:30 PM
Glad you got that sorted but your assumption about the postback is not fully correct though. When postback occurs, all the events that would run for the first time request would fire plus an event handler of the control that caused the postback will fire too (given one is provided) so, in effect, postback is a superset of the usual request.

Bug [MCSD]
6/17/2004 8:12:01 AM

Similar Artilces:

Should I use DataGrid(add dynamic control) or just dynamic control?
Hi, I am debating between using just dynamic control's or actually adding the control's dynamically into a datagrid.  I have tried with just adding dynamically, but I am having so much trouble because the selectedindexchanged even it firing for no reason.  I have asked a lot of people, but nobody knows the answer for that and I searched in the web and I am not getting anything either. Now someone suggested to use DataGrid and add the control's dynamically.  In each row, I have a dynamic column, which could be 2 and above.  It will depends on a number that I get fromt he ...

Dynamically name columns in dynamically created datagrid
I am using code that I found on the net to take a datatable, drop it into a datagrid, and then export the whole thing as an excel spreadsheet. So far for the small numberes I have tried it works. Currently I have an application where the number of columns ranges between 40 and 70. The problem that I have is I want the first row to have names which are meaningful to the user, but I don't want to rename my datatable columns, only the datagrid columns. Right now the Excel column names are the same as the datatable names. Those names are meaningful to me (the programmer) but meaningless to...

Dynamic Controls Within Dynamic Controls
Ok, So here's what i'm trying to do: I have the first set of controls, on the page which are dynamicly added, i'll just show simplified code, do to the complex nature of the full thing, so this is part one: private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) Label1.Text = ""; for (int i = 0; i < 10; i++) { Button li = new Button(); li.Text = "Click Me - " + i.ToString(); li.ID = i.ToString();   li.Click +=new EventHandler(li_Click); PlaceHolder1.Controls.Add(li); PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));   } } N...

Problems adding a dynamic control in a datagrid (with dynamic colums)
Basically I have an editable datagrid that will display any number of columns depending on what the current datasource is. When I want to edit a row I want each cell in the edit row to have two controls. The textbox control that contains the data being edited and button control that will move the text from the textbox to a large multi-line text box in a different panel. I am able to create the button dynamically however can't seem to get the click event to fire. Here is what I'm doing. Any help would be apreciated. My hunch is that I shouldn't be using the Page_Render event ...

postback from dynamic controls to create more dynamic controls
Hi, Could any one help me?  I have a masterpage with dynamically created list boxes.  When the user selects an item from the listbox the selected value will be used to dynamically create a set of controls in the contentplaceholder.  The problem i have is that the item selected from the list box is posted back and i do not know what the selected item is until the life cycle is complete.  During the post back is there a way to findout which listbox control performed a post back and its value before i get to the init part of the content page where i woul...

Dynamically adding columns with controls to a Datagrid
Hi all, I want to dynmically add rows and columns to a datagrid and also add controls(Textbox, dropdowns, etc) to the dynamically created cells. Please help with example codes. regards Subhajit Hi, Take a look @ : - Creating Controls Dynamically in ASP.NET - Creating DataGrid Programmatically - Creating DataGrid Templated Columns Dynamically HTHK B ShajudeenAreYaar.comDubai, United Arab Emirates....

Dynamic Slave Controls
I am working a solution to enhance slave controls. I have created a proof of concept based on the 2.04 code base that shows how to load slave controls without switching to the admin view. I have included a sample module that contains 3 view controls. Each control has a row of buttons that can be used to load one of the other 2 controls. (and no I am not using panels.) The default control has a drop down of other instances of the dynamic control that exist on the current tab. Using the module communicator you can raise an event from one control that tells another instance of the module what c...

Access dynamically added controls in datagrid column
Hi everyone,does anyone have any idea how to access the value in control in dynamically added column in datagrid?I have this 1 datagrid (datadatagrid) containing a list of data with checkboxes on each record.Once the checkbox is checked, it will be added dynamically to another datagrid (resultdatagrid) with a column in this datagrid containing a dropdownlist control.However when i want to access this resultdatagrid, it did not detect the controls.Does anyone have any idea why? and how to access this control in the dynamically added columns in the datagrid?Thanks..~lydia~...

Dynamic add control to a DataGrid ItemTemplate column
Basically I need to add from 1-N buttons in a column of a datagrid depending on data from the current row.  I'm assuming I'm missing something simple.  I can trace through and it goes through the code where it adds the buttons they just don't show up and I look at the source and they aren't there either. Here's the abbreviated code:aspx -------------------------------- <asp:datagrid id="dgAnimals" runat="server" ShowFooter="True" AutoGenerateColumns="False" OnItemCommand="dgAnimals_ItemCommand" GridLines="None"> <Columns> ...

Help with dynamic controls and retrieving data from dynamic controls
I am new to web development. My requirement is Text boxes get generated dynamically based on user input on click of a button called Ok after user enters values to these textboxes when user clicks on submit button ,values user entered to these textboxes have to be retrieved for further calculation I am generating text boxes in the ok button click event how to retrieve value user enters to these n where the procedure for that to be placed here u need to give name to id of every texbox in a specugic patterns so than u can know next time.   static int i = 0;protected...

Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls
I have been searching forever. Here is my problem. I have form of 3 panels of information for car insurance information. 1st panel is general information but I need to retrieve the NUMBER OF FAMILY members to see how many names I need for my next panel that is dynamically generated based upon my drop down list selection. I can generate panel 2 with the number of names I need but the problem is then posting the data from the textboxes to the next page. ERROR: Object reference not set to an instance of an object. I try to retrieve from a dynamic box txt1, txt2, etc. I have trie...

dynamic properties on dynamic controls
Hi Guys,I have a list of controls (i.e. 'control1.ascx', 'control2.ascx') in a table which i can dynamically add to my page and another associated table which holds the values for the parameters of each control (i.e. 'testText','numberOfResults').I can use the loadControl(ControlPathHere) method to add the controls to the page, however i need to be able to then look up the associated parameters for that control and set the appropriate properties.  Any idea how i can dynamically set these poperties for the dynamic controls. Alex. Ove...

Dynamic Gridview with dynamic controls
Hi, I’m trying to insert some dynamic linkbutton inside the rows of a gridview. 1. I First generate the columns inside a datatable. //Create an instance of DataTable DataTable dt = new DataTable(); DataColumn dcol = new DataColumn(”Measure”, typeof(System.String)); dt.Columns.Add(dcol); for (int i = 1; i < 5; i++) { //Create an ID column for adding to the Datatable dcol = new DataColumn(i.ToString(), typeof(LinkButton)); dt.Columns.Add(dcol); } 2.then, I created a row and add it to the datata...

Dynamic Row, Column & TextBox Control In Datagrid....
Hi,I have to create a  datagrid for my aspx page. The datagrid columns and rows are determined at run time. Even the column name is not a constant ones. I got the solution for column and rows. But now I want to add a text box control for each column and each row of the grid. How can I do it dynamically?Thanks & Regards,KK hello you can use template column anytime Yeah, thats what I'm trying out... But I'm not getting some good pointers on how to do it. The other problem for me is I want to add a column to a datagrid which is not bound to any columns...It will ...

Web resources about - Dynamic Datagrid - with dynamic columns - asp.net.presentation-controls

Want to preview our new DataGrid for Xamarin.Forms?
tl;dr Zumero.DataGrid is a Xamarin.Forms control for displaying data in rows and columns. If you would be interested in testing and previewing ...

Mad King DataGrid
This post is about scrolling in WPF and the egocentric DataGrid control. I’ll give the project background but if all you’re interested in is ...

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 295 ...

Microsoft Silverlight - Wikipedia, the free encyclopedia
Microsoft Silverlight is an application framework for writing and running rich Internet applications , with features and purposes similar to ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Casaba Security » Products » X5s Testing Tool For Finding XSS Vulnerabilities
Security analysis, consulting, development and testing partners who understand your business strategy.

CodeGuru - Microsoft developers related ideas, articles, tips, tricks, comments, downloads, and so much ...
CodeGuru is where developers can come to share ideas, articles, questions, answers, tips, tricks, comments, downloads, and so much more related ...

Caliburn Micro: WPF, Silverlight, WP7 and WinRT/Metro made easy.
A small, yet powerful framework designed for WPF, Silverlight and WP7. It implements a variety of UI patterns for solving real-world problems. ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 11 Jul 2012

license-discuss@opensource.org: 11636: first draft of license proliferation committee report
FYI,the first draft report of the OSI's License Proliferation Committee.To join the OSI's license proliferation discuss email list, send anemail ...

Resources last updated: 12/14/2015 7:19:30 PM