Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to catch or reserve the value of the controls that were created by dynamic?

How to catch or reserve the value of the controls that were created by dynamic?

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nettutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    astcws
    wrote on last edited by
    #1

    Hi,there. I am a new guy of asp.net:-O and hope to learn it better. I hope to use the datagrid to bind data and change its editmode by dynamic. I do this because my datasource is unknow and I won't know how many columns will the datasource have,either. That's why I need to make the datagrid dynamic. My code is below. I write some code at the onitembound event of the datagrid, and catch the edititemindex of the datagrid if it is not -1. Then, I catch the edititem and its controls, and replace it, change its cells columnspan..... But,however :(,I don't know how to reserve the value of the controls that I created:doh:. Because of the cycle of Asp.Net, all of them will dispear before the datagrid.updatecommand events was fired. I am still not very familiar with the cycle of asp.net and its events:confused:. Can someone teach me what should I do in the next step or this is still a wrong way:)? <%@ Page Language="VB" AutoEventWireup="True"%> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> Function CreateDataSource() As ICollection ' Create sample data for the DataGrid control. Dim dt As DataTable = New DataTable() Dim dr As DataRow ' Define the columns of the table. dt.Columns.Add(New DataColumn("IntegerValue", GetType(Integer))) dt.Columns.Add(New DataColumn("StringValue", GetType(String))) dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double))) ' Populate the table with sample values. Dim i As Integer For i = 0 to 8 dr = dt.NewRow() dr(0) = i dr(1) = "Item " & i.ToString() dr(2) = 1.23 * (i + 1) dt.Rows.Add(dr) Next i ' Create a DataView from the DataTable. Dim dv As DataView = New DataView(dt) Return dv End Function sub binddata() ItemsGrid.DataSource = CreateDataSource() ItemsGrid.DataBind() end sub Sub Page_Load(sender As Object, e As EventArgs) ' Load sample data only once when the page is first loaded. If Not IsPostBack Then binddata() End If End Sub 'I catch the edititemindex and change it below. sub itemsgridbound(sender as object, e as DataGridItemEventArgs) if itemsgrid.edititemindex <> -1 then if e.item.itemindex</x-turndown>

    S C A 4 Replies Last reply
    0
    • A astcws

      Hi,there. I am a new guy of asp.net:-O and hope to learn it better. I hope to use the datagrid to bind data and change its editmode by dynamic. I do this because my datasource is unknow and I won't know how many columns will the datasource have,either. That's why I need to make the datagrid dynamic. My code is below. I write some code at the onitembound event of the datagrid, and catch the edititemindex of the datagrid if it is not -1. Then, I catch the edititem and its controls, and replace it, change its cells columnspan..... But,however :(,I don't know how to reserve the value of the controls that I created:doh:. Because of the cycle of Asp.Net, all of them will dispear before the datagrid.updatecommand events was fired. I am still not very familiar with the cycle of asp.net and its events:confused:. Can someone teach me what should I do in the next step or this is still a wrong way:)? <%@ Page Language="VB" AutoEventWireup="True"%> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> Function CreateDataSource() As ICollection ' Create sample data for the DataGrid control. Dim dt As DataTable = New DataTable() Dim dr As DataRow ' Define the columns of the table. dt.Columns.Add(New DataColumn("IntegerValue", GetType(Integer))) dt.Columns.Add(New DataColumn("StringValue", GetType(String))) dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double))) ' Populate the table with sample values. Dim i As Integer For i = 0 to 8 dr = dt.NewRow() dr(0) = i dr(1) = "Item " & i.ToString() dr(2) = 1.23 * (i + 1) dt.Rows.Add(dr) Next i ' Create a DataView from the DataTable. Dim dv As DataView = New DataView(dt) Return dv End Function sub binddata() ItemsGrid.DataSource = CreateDataSource() ItemsGrid.DataBind() end sub Sub Page_Load(sender As Object, e As EventArgs) ' Load sample data only once when the page is first loaded. If Not IsPostBack Then binddata() End If End Sub 'I catch the edititemindex and change it below. sub itemsgridbound(sender as object, e as DataGridItemEventArgs) if itemsgrid.edititemindex <> -1 then if e.item.itemindex</x-turndown>

      S Offline
      S Offline
      S Sansanwal
      wrote on last edited by
      #2

      As you are adding controls dynamically and wants to access them after PostBack, you need to create them again after the PostBack Check http://www.codeproject.com/Purgatory/ViewState\_\_\_Dynamic\_Cntrl.asp Sanjay Sansanwal www.sansanwal.com

      1 Reply Last reply
      0
      • A astcws

        Hi,there. I am a new guy of asp.net:-O and hope to learn it better. I hope to use the datagrid to bind data and change its editmode by dynamic. I do this because my datasource is unknow and I won't know how many columns will the datasource have,either. That's why I need to make the datagrid dynamic. My code is below. I write some code at the onitembound event of the datagrid, and catch the edititemindex of the datagrid if it is not -1. Then, I catch the edititem and its controls, and replace it, change its cells columnspan..... But,however :(,I don't know how to reserve the value of the controls that I created:doh:. Because of the cycle of Asp.Net, all of them will dispear before the datagrid.updatecommand events was fired. I am still not very familiar with the cycle of asp.net and its events:confused:. Can someone teach me what should I do in the next step or this is still a wrong way:)? <%@ Page Language="VB" AutoEventWireup="True"%> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> Function CreateDataSource() As ICollection ' Create sample data for the DataGrid control. Dim dt As DataTable = New DataTable() Dim dr As DataRow ' Define the columns of the table. dt.Columns.Add(New DataColumn("IntegerValue", GetType(Integer))) dt.Columns.Add(New DataColumn("StringValue", GetType(String))) dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double))) ' Populate the table with sample values. Dim i As Integer For i = 0 to 8 dr = dt.NewRow() dr(0) = i dr(1) = "Item " & i.ToString() dr(2) = 1.23 * (i + 1) dt.Rows.Add(dr) Next i ' Create a DataView from the DataTable. Dim dv As DataView = New DataView(dt) Return dv End Function sub binddata() ItemsGrid.DataSource = CreateDataSource() ItemsGrid.DataBind() end sub Sub Page_Load(sender As Object, e As EventArgs) ' Load sample data only once when the page is first loaded. If Not IsPostBack Then binddata() End If End Sub 'I catch the edititemindex and change it below. sub itemsgridbound(sender as object, e as DataGridItemEventArgs) if itemsgrid.edititemindex <> -1 then if e.item.itemindex</x-turndown>

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Or, an alternative answer to S Sansanwal would be to examine the Request.Form collection which will contain the values of the controls. You will need to give each of your dynamically created controls a unique ID so that you can pick them out of the collection.


        "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!

        1 Reply Last reply
        0
        • A astcws

          Hi,there. I am a new guy of asp.net:-O and hope to learn it better. I hope to use the datagrid to bind data and change its editmode by dynamic. I do this because my datasource is unknow and I won't know how many columns will the datasource have,either. That's why I need to make the datagrid dynamic. My code is below. I write some code at the onitembound event of the datagrid, and catch the edititemindex of the datagrid if it is not -1. Then, I catch the edititem and its controls, and replace it, change its cells columnspan..... But,however :(,I don't know how to reserve the value of the controls that I created:doh:. Because of the cycle of Asp.Net, all of them will dispear before the datagrid.updatecommand events was fired. I am still not very familiar with the cycle of asp.net and its events:confused:. Can someone teach me what should I do in the next step or this is still a wrong way:)? <%@ Page Language="VB" AutoEventWireup="True"%> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> Function CreateDataSource() As ICollection ' Create sample data for the DataGrid control. Dim dt As DataTable = New DataTable() Dim dr As DataRow ' Define the columns of the table. dt.Columns.Add(New DataColumn("IntegerValue", GetType(Integer))) dt.Columns.Add(New DataColumn("StringValue", GetType(String))) dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double))) ' Populate the table with sample values. Dim i As Integer For i = 0 to 8 dr = dt.NewRow() dr(0) = i dr(1) = "Item " & i.ToString() dr(2) = 1.23 * (i + 1) dt.Rows.Add(dr) Next i ' Create a DataView from the DataTable. Dim dv As DataView = New DataView(dt) Return dv End Function sub binddata() ItemsGrid.DataSource = CreateDataSource() ItemsGrid.DataBind() end sub Sub Page_Load(sender As Object, e As EventArgs) ' Load sample data only once when the page is first loaded. If Not IsPostBack Then binddata() End If End Sub 'I catch the edititemindex and change it below. sub itemsgridbound(sender as object, e as DataGridItemEventArgs) if itemsgrid.edititemindex <> -1 then if e.item.itemindex</x-turndown>

          A Offline
          A Offline
          astcws
          wrote on last edited by
          #4

          Ok,I got it. Thanks a lot.

          1 Reply Last reply
          0
          • A astcws

            Hi,there. I am a new guy of asp.net:-O and hope to learn it better. I hope to use the datagrid to bind data and change its editmode by dynamic. I do this because my datasource is unknow and I won't know how many columns will the datasource have,either. That's why I need to make the datagrid dynamic. My code is below. I write some code at the onitembound event of the datagrid, and catch the edititemindex of the datagrid if it is not -1. Then, I catch the edititem and its controls, and replace it, change its cells columnspan..... But,however :(,I don't know how to reserve the value of the controls that I created:doh:. Because of the cycle of Asp.Net, all of them will dispear before the datagrid.updatecommand events was fired. I am still not very familiar with the cycle of asp.net and its events:confused:. Can someone teach me what should I do in the next step or this is still a wrong way:)? <%@ Page Language="VB" AutoEventWireup="True"%> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> Function CreateDataSource() As ICollection ' Create sample data for the DataGrid control. Dim dt As DataTable = New DataTable() Dim dr As DataRow ' Define the columns of the table. dt.Columns.Add(New DataColumn("IntegerValue", GetType(Integer))) dt.Columns.Add(New DataColumn("StringValue", GetType(String))) dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double))) ' Populate the table with sample values. Dim i As Integer For i = 0 to 8 dr = dt.NewRow() dr(0) = i dr(1) = "Item " & i.ToString() dr(2) = 1.23 * (i + 1) dt.Rows.Add(dr) Next i ' Create a DataView from the DataTable. Dim dv As DataView = New DataView(dt) Return dv End Function sub binddata() ItemsGrid.DataSource = CreateDataSource() ItemsGrid.DataBind() end sub Sub Page_Load(sender As Object, e As EventArgs) ' Load sample data only once when the page is first loaded. If Not IsPostBack Then binddata() End If End Sub 'I catch the edititemindex and change it below. sub itemsgridbound(sender as object, e as DataGridItemEventArgs) if itemsgrid.edititemindex <> -1 then if e.item.itemindex</x-turndown>

            S Offline
            S Offline
            S Sansanwal
            wrote on last edited by
            #5

            Refer http://www.codeproject.com/Purgatory/ViewState\_\_\_Dynamic\_Cntrl.asp and http://weblogs.asp.net/ksamaschke/archive/2003/04/27/6098.aspx Sanjay Sansanwal www.sansanwal.com

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups