User Control in Datagrid without TemplateColumn

Discussion in 'ASP .Net' started by Guest, Jul 2, 2005.

  1. Guest

    Guest Guest

    Hi all,

    Have a question from the following post to create user control in a
    Datagrid....

    http://www.dotnet247.com/247reference/msgs/45/225337.aspx

    I have a question.... I can create the User control in the Datagrid... and
    that is a run time user control in the datagrid.. without using the
    <templatecolumn> in the datagrid... and on ItemCreated Event i create the
    user control in the datagrid.

    Now if i want to get the value out of the datagrid on a button click how m i
    supose to get as when i say

    Below is the code to add a user control in the cell (0).... of my datagrid
    at runtime
    Private Sub DgrdRunning_ItemCreated(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    DgrdRunning.ItemCreated
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = _
    ListItemType.AlternatingItem Then
    'always insert the dataelement name into the first column as a
    label.
    Dim MyControl As Control =
    LoadControl("..\Common\UserDateControl.ascx")
    e.Item.Cells(0).Controls.Add(MyControl )
    MyControl .ID = "MyUserControl"
    MyControl .value= e.Item.Cells(0).Text
    End If
    End sub


    Here is the code to get the value out of the datagrid's user contro which i
    added...

    For Each Item As DataGridItem In DgrdRunning.Items
    Dim MyDate as string
    MyDate = CType (Item.Cells(0).FindControl("MyUserControl"),
    UserDateControl).value
    Next
    It doesnt give me the new value which a user has input on the user
    control..and it gives me a error that object ref. not set to an instance...

    But if do it using the templatecolumn then it gets the new value... dont
    know what i m doing wrong...

    May be i might be wrong... Somewhere

    Plz Help

    Cheers
    C
     
    Guest, Jul 2, 2005
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.