By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,969 Members | 2,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,969 IT Pros & Developers. It's quick & easy.

User Control in Datagrid without TemplateColumn

P: n/a
Hi all,

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

http://www.dotnet247.com/247referenc...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

Nov 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.