dynamic binding of datas with item template containing drop down list created dynamically in the datagrid


hai every body ,

i have to to do following

1.creation of  n- number of  dynamic headers  where n is number of values in the datacolumn(table of database)at
2.creation of n-number of dynamic template columns  dynamically with drop down lists in it.

i have to create data grid with dynamic template column created having drop down list in each temlate column
the following code is written under the page load of webform containing datagrid DGdashboard

i have completed the above task with following code to come .

I could not create dropdownlist with unique name so i can edit the data with findcontrolby('dropdownlistname') and save to database.
if any of can resolve my problem ...reply back.



Dim
tc As New TemplateColumn

Dim i As Integer

Dim dc As New BoundColumn

Dim lstrHeader As String

 

For i = 1 To 30 (this creates 30 template columns for each iteration)

 

tc.HeaderTemplate = New DataGridTemplate(ListItemType.Header, "Priority")

tc.ItemTemplate = New DataGridTemplate(ListItemType.Item, "Column1")

tc.EditItemTemplate = New _

DataGridTemplate(ListItemType.EditItem, "Priority")

'tc(i).FooterTemplate = New _

' DataGridTemplate(ListItemType.Footer, "Column1")

DGdashboard.Columns.Add(tc)

Next

Dim tc2 As New TemplateColumn

tc2.HeaderTemplate = New _

DataGridTemplate(ListItemType.Header, "Column2")

tc2.ItemTemplate = New _

DataGridTemplate(ListItemType.Item, "Column2")

tc2.EditItemTemplate = New _

DataGridTemplate(ListItemType.EditItem, "Column2")

tc2.FooterTemplate = New _

DataGridTemplate(ListItemType.Footer, "Column2")

DGdashboard.Columns.Add(tc2)

objDA.Fill(objds)

DGdashboard.DataSource = objds

DGdashboard.DataBind()

End If


the following class constructor is called for the generation of template columns in the datagrid



Public
Class DataGridTemplate

Implements ITemplate

Dim templateType As ListItemType

Dim columnName As String

Dim iCount As Integer

Sub New(ByVal type As ListItemType, ByVal ColName As String)

templateType = type

columnName = ColName

End Sub

Sub InstantiateIn(ByVal container As Control) _

Implements ITemplate.InstantiateIn

Dim lc As New DropDownList

Dim lbl As New Label

Dim status As New ArrayList

With status

.Add("Ready")

.Add("30-40")

.Add("40-60")

End With

Select Case templateType

Case ListItemType.Header

lbl.Text = "<B>" & columnName & "</B>"

lc.DataSource = status   (binding status array to all dropdown list )

container.Controls.Add(lbl)

Case ListItemType.Item

lc.ID = "Item " & iCount

lc.DataSource = status

lc.BackColor = Color.SkyBlue

lc.ForeColor = Drawing.Color.DarkBlue

container.Controls.Add(lc)

Case ListItemType.EditItem

'Dim tb As New TextBox

'tb.Text = ""

lc.DataSource = status

container.Controls.Add(lc)

Case ListItemType.Footer

lc.ID = "<I>Footer</I>"

container.Controls.Add(lc)

End Select

End Sub

End Class

regards
karthik.P

0
karthi_216
8/8/2005 5:21:32 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
807 Views

Similar Articles

[PageSpeed] 13
Get it on Google Play
Get it on Apple App Store

Try inheriting your DataGridTemplate from INamingContainer interface. This interface creates a unique id for each control.
0
aspdotnetv2
8/8/2005 4:58:16 PM

hai frenz,

i have given unique name to the  controls in the each row of the datagrid . i also have loaded combo box with values in array list.
now i have to provide editing facilitites to data in combo box .but when button is clicked datagrid's dynamic template column and databound column is getting lost (during postback) .

this my code ...

I have called fill grid method in load event
i have called save combo values under button event(this where datagrid's template column is getting lost)

Private Function FillGrid()

Dim i As Integer

Dim lstrMarketName As String

Dim lstrInitiativeName As String

Dim lstrPriority As Integer

Dim lstrpublishtype As String

Dim lstrHeader As String

1st databound column
Dim
dcpriority As New BoundColumn

dcpriority.HeaderText = "Priority"

dcpriority.DataField = "Priority"

DGdashboard.Columns.Add(dcpriority)

2nd databound column
Dim
dc As New BoundColumn

dc.HeaderText = "Initiative Name"

dc.DataField = "InitiativeName"

DGdashboard.Columns.Add(dc)

3rd databound column
Dim
dcpublishtype As New BoundColumn

dcpublishtype.HeaderText = "Publish Type"

dcpublishtype.DataField = "PublishType"

DGdashboard.Columns.Add(dcpublishtype)

mudtDashBoard.GetDetails()

dt = mudtDashBoard.mudtEntityLoader.ds.Tables("InitiativeName")

number of markets(marketsfield) in market table=n
 creating n number of itemtemplate column

For i = 0 To mudtDashBoard.mudtEntityLoader.ds.Tables("MarketName").Rows.Count - 1

Dim tc As New TemplateColumn

lstrMarketName = mudtDashBoard.mudtEntityLoader.ds.Tables("MarketName").Rows(i).Item("MarketName")

tc.HeaderText = lstrMarketName

tc.ItemTemplate = New DataGridTemplate(ListItemType.Item, lstrMarketName)

tc.EditItemTemplate = New _

DataGridTemplate(ListItemType.EditItem, lstrMarketName)

tc.FooterTemplate = New _

DataGridTemplate(ListItemType.Footer, lstrMarketName)

DGdashboard.Columns.Add(tc)

Next

DGdashboard.AutoGenerateColumns = False

'Calls the Function for setting Corresponding Values in Combo Boxes

Call SetComboValues()

DGdashboard.DataSource = dt

DGdashboard.DataBind()

End Function

Private Function SetComboValues()

Try

Dim lintLoopCounter As Integer

Dim lintMarketTableCount As Integer

Dim lintInitiativeTableCount As Integer

Dim lintStatusTableCount As Integer

Dim lcboStatus As DropDownList

Dim lstrComboId As String

Dim lintStatusId As Integer

Dim lintStatusRowId As Integer

For lintInitiativeTableCount = 0 To DGdashboard.Items.Count - 1

For lintMarketTableCount = 0 To mudtDashBoard.mudtEntityLoader.ds.Tables("MarketName").Rows.Count - 1

For lintStatusTableCount = 0 To mudtDashBoard.mudtEntityLoader.ds.Tables("SetStatus").Rows.Count - 1

lstrComboId = mudtDashBoard.mudtEntityLoader.ds.Tables("MarketName").Rows(lintMarketTableCount).Item("MarketName")

lcboStatus = DGdashboard.Items(lintInitiativeTableCount).FindControl(lstrComboId)

If mudtDashBoard.mudtEntityLoader.ds.Tables("MarketName").Rows(lintMarketTableCount).Item("MarketId") = mudtDashBoard.mudtEntityLoader.ds.Tables("SetStatus").Rows(lintStatusTableCount).Item("MarketId") And _

mudtDashBoard.mudtEntityLoader.ds.Tables("InitiativeName").Rows(lintInitiativeTableCount).Item("InitiativeId") = mudtDashBoard.mudtEntityLoader.ds.Tables("SetStatus").Rows(lintStatusTableCount).Item("InitiativeId") Then

lcboStatus.SelectedIndex = Global.getIndexByAttribute(lcboStatus, mudtDashBoard.mudtEntityLoader.ds.Tables("SetStatus").Rows(lintStatusTableCount).Item("StatusId"))

Exit For

End If

Next

Next

Next

Catch ex As Exception

HandleException(ex)

End Try

End Function


Private
Function savecombovalues()

Dim lintInitiativeTableCount As Integer

Dim ldr As DataRow

Dim lintMarketTableCount As Integer

Dim lstrComboId As String

Dim lcboStatus As DropDownList

Dim linitiative As String

Dim lmarket As String

For lintInitiativeTableCount = 0 To mudtDashBoard.mudtEntityLoader.ds.Tables("InitiativeName").Rows.Count - 1

For lintMarketTableCount = 0 To mudtDashBoard.mudtEntityLoader.ds.Tables("MarketName").Rows.Count - 1

lstrComboId = mudtDashBoard.mudtEntityLoader.ds.Tables("MarketName").Rows(lintMarketTableCount).Item("MarketName")

lcboStatus = DGdashboard.Items(lintInitiativeTableCount).FindControl(lstrComboId)

If (lcboStatus.SelectedIndex <> 4) Then

linitiative = mudtDashBoard.mudtEntityLoader.ds.Tables("InitiativeName").Rows(lintInitiativeTableCount).Item("InitiativeId")

lmarket = mudtDashBoard.mudtEntityLoader.ds.Tables("MarketName").Rows(lintMarketTableCount).Item("marketid")

ldr = mudtDashBoard.mudtEntityLoader.ds.Tables("Market2initiative").NewRow()

ldr.Item("MarketId") = lmarket

ldr.Item("InitiativeId") = linitiative

ldr.Item("StatusId") = lcboStatus.SelectedIndex

ldr.Item("Obsolete") = 0

ldr.Item("CreationUser") = mudtUser.strUserName

ldr.Item("CreationDate") = Now.Date

mudtDashBoard.mudtEntityLoader.ds.Tables("Market2initiative").Rows.Add(ldr)

End If

Next

Next

End Function



Now the template creation class follows

Public Class DataGridTemplate

Implements ITemplate

Private mudtUser As userManagement.User

Dim templateType As ListItemType

Dim columnName As String

Dim iCount As Integer

Dim conn As New SqlConnection("workstation id=HARMONY;packet size=4096;user id=sa;password='jaigurudev';data source=DBSERVER;persist security info=False;initial catalog=CMDDB")

Dim objDA As New SqlDataAdapter("select status from status", conn)

Dim objds As New DataSet

'Dim lintdt As New DataTable

Dim status As New ArrayList

Dim mdtstatus As DataTable

 

Public Property udtUser() As userManagement.User

Get

Return (mudtUser)

End Get

Set(ByVal Value As userManagement.User)

mudtUser = Value

End Set

End Property

Public Function GetStatus()

Try

Dim lstrSQL As String

''Check the Number of Rows in Initiative Table Greater than zero

'If mdtInitiativeList.Rows.Count > 0 Then

' 'Clears the Rows in InitiativeTable

' mdtInitiativeList.Rows.Clear()

'End If

'Getting the list of Initiative From the Initiative Table

lstrSQL = "select * from status"

'Getting the Details from the Initiative Table

mdtstatus = gudtdbas.GetTable(lstrSQL, "CMD", "jaigurudev")

Catch ex As Exception

Throw ex

End Try

End Function

Sub New(ByVal type As ListItemType, ByVal ColName As String)

templateType = type

columnName = ColName

'objDA.Fill(objds, "status")

'mdtstatus = objds.Tables("status")

Call GetStatus()

Dim lstrstatus As String

'For lintLoopCounter = 0 To mdtstatus.Rows.Count - 1

' lstrstatus = mdtstatus.Rows(lintLoopCounter).Item("Status")

' With status

' .Add(lstrstatus)

' End With

'Next

End Sub

Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn

Dim lc As New DropDownList

Dim lbl As New Label

Dim lintLoopCounter As Integer

Dim lintStatusId As Integer

Dim lstrStatus As String

Select Case templateType

Case ListItemType.Header

lbl.Text = "<B>" & columnName & "</B>"

container.Controls.Add(lbl)

Case ListItemType.Item

lc.ID = columnName

lc.SelectedIndex = 4

lc.CssClass = "FormsControls"

lc.Width = System.Web.UI.WebControls.Unit.Pixel(50)

lc.Height = Unit.Pixel(5)

 

For lintLoopCounter = 0 To mdtstatus.Rows.Count - 1

lstrStatus = mdtstatus.Rows(lintLoopCounter).Item("Status")

lintStatusId = mdtstatus.Rows(lintLoopCounter).Item("StatusID")

lc.Items.Add(lstrStatus)

lc.Attributes.Add(lstrStatus, lintStatusId)

Next

container.Controls.Add(lc)

Case ListItemType.EditItem

lc.ID = columnName

container.Controls.Add(lc)

End Select

End Sub

End Class

I think i have clearly given my problem and code so try out it may be useful for u also..
reply  me if any one could find solutions kindly reply me about it ...

regards
karthik.P

0
karthi_216
8/11/2005 5:08:44 AM
Reply:

Similar Artilces:

create and add controls dynamically to dynamically created Table Control
How can i create web server Table control dynamically with vary number of  rows and columns, and  then adding  further  other controls(like  dropdown, Text box etc.)  randomly to the specific created Table Cells. First of all you should use PlaceHolder control to add Table control to it:<asp:PlaceHolder id="PH" runat="server"></asp:PlaceHolder>Code Behinde:Table t = new Table();TableRow tr = new TableRow();TableCell td = new TableCell();//td.Text = "Hello, I am a TD";// Here well create TextBox and add it to TDTextBox txt = new TextBox();tx...

Create Dynamic Dropdownlist Controls / How to Create Dynamic Dropdownlist Controls
Hi,    This might be useful for someone who strucks with create dynamic dropdownlist/ controls. In ASP.Net is page is stateless. when you are creating the dynamic dropdownlist control following issues you might be facing, 1. After loaded the control, on selected index changed event the control will be disappear. 2. The selectedIndexChanged raised event might not be fired when selection of Dropdownlist. 3. Locate the exact dropdownlist which you created dynamically. 4.Placing this dynamic controls in exact location in the page. Solution: You have to re-create the con...

Dynamically add Container.Data Items/Hyperlinks to Item Template.
Here is what I have so far. <code> Public Function PopDLProjectItems() As String Select Case Request.QueryString("Mode") Case 0 Return ("<asp:HyperLink id='Hyperlink2' NavigateUrl='./Project.aspx?' runat='server'>Select</asp:HyperLink>") Case 1 Return ("<asp:HyperLink id=""Hyperlink2"" NavigateUrl=""./Project.aspx?"" runat=""server"">Select</asp:HyperLink>") Case 2 Return ("<asp:HyperLink id=""Hyperlink2"" NavigateUrl='<%# ""./Project.aspx?ID="" & Container.DataItem(""Project_ID"")&""&Mode=Edit""%>' runat=""server"">Select</as...

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 Bind Drop Down List in Data Grid
Hi How do i dynamically bind the drop down list in data grid ? My question is i have bounded drop down list in to my data grid its working pretty fine even during edit but just see this EX:- Imagin we have three drop down list in an edited datagrid 1)Drop Down contain all the deliverable code and deliverable Name 2)Drop Down contain all the Milestone code and Milestone Name w.r.t deliverable code 3)Drop Down contain all the Activity code and Activity Name w.r.t Milestone code now by default all these drop down list is filed in edit mode of data grid when i change th...

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...

Bubbling Events on Dynamically created controls that are on dynamically created user-controls on a module!! HELP MAH PUHLEASE!
I may be cross posting this question, but I am really going to go crazy.. Please help if you can!I think I am going to go mad. If anyone can help me with this small issue, I will build an idol in your image made of clay, and have nubile maidens dance in front of it in worship!!!!I have a module. Let's call it Module-1Module-1 Connects to a database and gets a list of items.Module-1 Then creates on the fly a number of buttons that represent that list of items.Each button when clicked dynamically creates a web-user control. Let's pull out 1 button, and 1 usercontrol and call them Button-1 and ...

Data Binding with Dynamically Created controls not working both ways
I am following this example: http://msdn.microsoft.com/en-us/library/y0h809ak(vs.71).aspx to create a template for a FormView at run time and insert a text box in the template.  It works as far as the article shows, you get the text box, bound to a column in the data.  But it does not work when you try to update the data in the form.  I did some testing on this and the OldValues and NewValues lists in the ItemUpdating event don't even show that the text box exists.  Somehow the FormView isn't binding the text box the same way it does when you do it with &...

Loading controls dynamically based of previously dynamically created control
Hi All, Heres the deal. I have a hierarchal or tree structure of data that needs to be represented in dropdownlists (ddl). The root is a single ddl and the items in the ddl are children of the root. When a child is selected I need to add another ddl to the control collection with it's children as listitems. Its like dropdownlist chaining without knowing the order of the dropdownlists. Now I know I can use the Page.OnInit method to add the ddl, but since viewstate is not loaded until after OnInit is called I don't have access to the selected child. Right know I am getting around this by u...

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 ...

Datagrid Dynamic Template Columns with a Data-Driven User Control
All, I am writing a dynamic datagrid that contains X number of columns. The columns are of type Template. Each cell contains a Web user control (which is a database-driven dropdown list). The problem I am having is that when I dynamically create the colum I have to data-bind the dropdown list and apperently it does not it exists. The Web user control works like a champ if I call it directly from another page. This is the error: Object reference not set to an instance of an object. Public Sub Load_List() Line 44: Line 45: Histopathology_Values_List.DataSource =...

Dynamicly modified items in a Datagrid item template
I have a datagrid that runs an OnItemCommand that converts the text to RED if it not a match in a database, signalling there was a change. The Datagrid is long so I'm trying to create an Item template which would have more than one of these items in one column. go from this <asp:BoundColumn DataField="firstname" HeaderText="First Name" /> <asp:BoundColumn DataField="middleinitial" HeaderText="MI" /> <asp:BoundColumn DataField="lastname" HeaderText="Last Name" /> .... to this <...

Dynamic Data Controls Template
 When i installed the latest CTP for ASP.NET Futures the Dynamic Data Controls Template is empty. No files except of the web.config and the references are in there. I install it on a machine that runs the RTM of VS 2008. Can you help me? Where can i alternatively get the full template?  (the DynamicDataWeb.zip file?) br, Marble We are now within a week or so of releasing a much newer updated version of this technology, so I suggest you just hold off on this for now for a little while longer! David...

Missing Dynamic Data Website and Dynamic Data Web Application templates
 I have installed VS 2008 SP1 and .Net 3.5 SP1 but I still don't see the Dynamic Data Website and Dynamic Data Web Application templates when I try to create a new website or web application. Hi, when you choose to add a new project make sure that the targeted framework is indeed 3.5 and that you select the C# or VB.NET root node or in the Web node. Normally they should be in there. When I installed it on one of my laptops I didn't see them either. I didn't check the 3.5 framework and apparently it stood on 3.0 causing me to go like  until I found it. ...

Web resources about - dynamic binding of datas with item template containing drop down list created dynamically in the datagrid - asp.net.presentation-controls

iPhone 5 A6 chip to dynamically up-clock up to 1.3GHz (and downclock too)?
Interesting video from our friends at TLDToday: If this is not just a Geekbench app glitch, it could indicate why that A6 processor is so 2X ...

Apple's Lightning port dynamically assigns pins to allow for reversible use
... a closer look at how Apple's new Lightning connector works, and has come to the conclusion that the 8 pins on each side of the plug are dynamically ...

iPhone 5 Lightning port dynamically reassigns pins
... of Apple's Lightning USB cable shows that the pins on the plug aren't arranged symmetrically, suggesting that the Lightning port can dynamically ...

Urlbox Launches Screenshots-as-a-Service Platform to Dynamically Update Galleries
... changes. Launched yesterday, Urlbox allows anyone with a gallery displaying website screenshots to automate the process and keep them dynamically ...

Everything.me launcher dynamically adapts to what you’re doing right now
... phone according to what you’re doing. Perform a search for ‘football’ and your background will change to the NFL logo. A launcher that dynamically ...


A YouTube Experiment Resizes the Player Dynamically
There's a new YouTube experiment that changes the video player's size, depending on the browser window's size. When resizing Chrome's window, ...

Apple Granted “Dynamically Changing Cursor for User Interface” Patent, Originally Filed in 2003
... a utility patent that covers the use of the mouse cursor that changes according to the context of the task it is engaged in. Called a “Dynamically ...

Atmel's FPSLIC II Dynamically Reconfigurable SoC Supports "Silicon-Sharing" For Peripherals & Interfaces ...
Silicon-Sharing Fits 200K Gate Design into 40K Gate FPSLIC II's, Cuts Power Drain by 97%

Everything.me Launcher Wants to Dynamically Change Phones Based on Location, Interests, and Mental State ...
What if your phone’s launcher dynamically changed based upon interests, your location, or topics you had in mind at a specific moment? A new ...

Resources last updated: 12/24/2015 6:28:25 AM