Professional Web Applications Themes

Changing the binding of a template column - ASP.NET Data Grid Control

I have a datagrid that is bound to different datasources. The datagrid contains a templated column (dropdown list). How do I change the selectedvalue binding to the different datasources? I can do this at design time by changing the datasource of the grid, going into the databindings popup and adjusted the selected item there... but I want to be able to do this in code depending on the dataset selected. Thanks in advance....

  1. #1

    Default Changing the binding of a template column

    I have a datagrid that is bound to different datasources.

    The datagrid contains a templated column (dropdown list).

    How do I change the selectedvalue binding to the different datasources? I
    can do this at design time by changing the datasource of the grid, going
    into the databindings popup and adjusted the selected item there... but I
    want to be able to do this in code depending on the dataset selected.

    Thanks in advance.


    Rob Edwards Guest

  2. #2

    Default RE: Changing the binding of a template column

    Hi Rob,

    I have reviewed your issue. Due to the nature of your issue I need to do
    additional research to determine the best way to provide assistance. I will
    contact you as soon as possible.

    Best regards,

    Jacob Yang
    Microsoft Online Partner Support
    Get Secure! C [url]www.microsoft.com/security[/url]
    This posting is provided "as is" with no warranties and confers no rights.

    Jacob Yang [MSFT] Guest

  3. #3

    Default RE: Changing the binding of a template column

    Hi Rob,

    If I didn't misunderstand you, you want to change the databinding
    properties on the dropdownlist control that is embedded into a Datagrid as
    a template column.

    If it is the case, we can hook certain event of the datagrid. In such an
    event, we can get an reference to the embedded dropdownlist control and do
    what we want against the control. For example, here is a sample, which
    hooks the ItemCreated event of the datagrid control. In this event, we use
    the FindControl method to locate the dropdownlist control and then bind it
    to an ArrayList object.

    Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    DataGrid1.ItemCreated
    Dim DropList As DropDownList =
    CType(e.Item.Cells(0).FindControl("DropDownList1") , DropDownList)
    If (Not DropList Is Nothing) Then
    If Not IsPostBack Then
    Dim myList As New ArrayList()
    myList.Add("Item 1")
    myList.Add("Item 2")
    myList.Add("Item 3")
    myList.Add("Item 4")
    myList.Add("Item 5")
    DropList.DataSource = myList
    DropList.DataBind()
    End If
    End If
    End Sub
    End Class

    Does it answer your question? If I have misunderstood your concern, please
    feel free to let me know.

    Best regards,

    Jacob Yang
    Microsoft Online Partner Support
    Get Secure! C [url]www.microsoft.com/security[/url]
    This posting is provided "as is" with no warranties and confers no rights.

    Jacob Yang [MSFT] Guest

Similar Threads

  1. Template column base on another column value
    By Esperanza in forum ASP.NET Data Grid Control
    Replies: 5
    Last Post: February 21st, 04:02 PM
  2. Replies: 2
    Last Post: April 29th, 05:16 PM
  3. Bound Column or Template Column (w dAdapater?) in DataGrid
    By Ravichandran Mahalingam in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: January 9th, 03:30 PM
  4. changing the template column's position ?
    By Gary in forum ASP.NET Data Grid Control
    Replies: 4
    Last Post: October 15th, 09:46 PM
  5. Data binding within a template
    By Barry in forum ASP.NET General
    Replies: 0
    Last Post: July 30th, 05:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139