Two DataGrids on One Form? Could be simple solution, but I can't findcontrol !!!

  • Thread starter Thread starter ssoss
  • Start date Start date
S

ssoss

I have the something like the following data structure:
Users
users_ID, orgs_ID, users_email, users_password, etc.
Orgs
orgs_ID, orgs_name, orgs_description, etc.

I have a single form with two datagrids.
I have loaded one dataset with two tables.
There is only a single record at any time in each of the tables in the bound
dataset.
I bind the first datagrid to one datatable, and the second datagrid to
another datatable.

Both datagrids seem to populate just fine in edit mode, but...

My UPDATE routine is fired on the update command of the first user_profile
datagrid.
SO THE PROBLEM IS:
I can't findcontrol for the org_id in the second datagrid.

The key issue here is the need to easily enable additional records to be
added to the second datagrid, to enable the registration of different orgs.

Anyone know about using multiple datagrids (not necessarily nested) on the
same page?
Just to prove I have NO idea what I'm doing, here's some of my code my code
(simplified)...

CODE SNIPPET
Private Sub user_profile_update(Sender As Object, E As
DataGridCommandEventArgs)
If page.isValid Then
Dim main_email As TextBox = e.Item.FindControl("main_email")
Dim main_password As TextBox = e.Item.FindControl("main_password")
Dim org_id As DropDownList = CType(FindControl("org_id"), DropDownList)

data_set = load_user_data()

Dim data_table as String
data_table = "main_identity"
If data_set.tables(data_table).Rows.Count > 0 Then
With data_set.tables(data_table).Rows(0)
.Item("main_email") = main_email.Text
.Item("main_password") = main_password.Text
.Item("org_id") = org_id.selecteditem.value <<<<<< ERROR

ERROR
System.NullReferenceException: Object reference not set to an
instance of an object.

End With
End If

user_profile.EditItemIndex = -1
org_profile.EditItemIndex = -1
bind_profiles()
ViewState("Add") = "Off"
ViewState("Edit") = "Off"
End If
End Sub

<form runat="server" name="profile">

<ASP:DataGrid
id="user_profile"
runat="server"
Autogeneratecolumns="false"
MaintainState="false"
Border="0"
Cellspacing="0"
Cellpadding="0"
ShowFooter="true"
OnEditCommand="user_profile_edit"
OnCancelCommand="user_profile_cancel"
OnUpdateCommand="user_profile_update"
DataKeyField="main_id">
<Columns>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel"
UpdateText="Update" />
<asp:BoundColumn DataField="main_id" ReadOnly="True" visible="false"/>
<asp:TemplateColumn>
<ItemTemplate>
Email Address: <%# Container.DataItem("main_email") %><br>
Password: <%# Container.DataItem("main_password") %><br>
</ItemTemplate>
<EditItemTemplate>
Email Address: <asp:TextBox id="main_email" Size="7" Text='<%#
Container.DataItem("main_email") %>' runat="server"/><br>
Password: <asp:TextBox id="main_password" Size="7" Text='<%#
Container.DataItem("main_password") %>' runat="server"/><br>
</EditItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:datagrid>

<ASP:DataGrid
id="org_profile"
runat="server"
Autogeneratecolumns="false"
MaintainState="false"
Border="0"
Cellspacing="0"
Cellpadding="0"
ShowFooter="false"
ShowHeader="false"
DataKeyField="org_id">
<Columns>
<asp:EditCommandColumn visible="false" EditText="Edit" CancelText="Cancel"
UpdateText="Update" />
<asp:BoundColumn DataField="org_id" ReadOnly="True" visible="false"/>
<asp:TemplateColumn>
<ItemTemplate>
Organization Name: <%# Container.DataItem("org_name") %><br>
Organization Type: <%# Container.DataItem("org_type_id") %><br>
</ItemTemplate>
<EditItemTemplate>
Organization Name:
<asp:dropDownList
id="org_id"
DataSource='<%#
load_dropdown_data("organization_company","org_id","org_name","Other") %>'
DataValueField="org_id"
DataTextField="org_name" runat="server"
SelectedValue = '<%# DataBinder.Eval(Container.DataItem,
"org_id")%>' />
</EditItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:datagrid>

</form>




Thanks!

Drew
ssoss
 
If I understand you correctly, you want to relate one datagrid to another
( Person )Master and ( Orgs ) Slave. scenario ?

If this is the case, you can define both tables in a single dataset and then
define the relationship between the two PK and FK.

Ok, now point the datasource of Grid one to the master and point the
datasource of the second to the relationship table2.relationshipname

This will link the two grids so clicking on the Person will give you the
related records in the second.


Regards OHM
 
Hi

Please look into the following msdn artcile:
http://msdn.microsoft.com/msdnmag/issues/03/08/DataGrids/d
efault.aspx

Ravikanth[MVP]

-----Original Message-----
I have the something like the following data structure:
Users
users_ID, orgs_ID, users_email, users_password, etc.
Orgs
orgs_ID, orgs_name, orgs_description, etc.

I have a single form with two datagrids.
I have loaded one dataset with two tables.
There is only a single record at any time in each of the tables in the bound
dataset.
I bind the first datagrid to one datatable, and the second datagrid to
another datatable.

Both datagrids seem to populate just fine in edit mode, but...

My UPDATE routine is fired on the update command of the first user_profile
datagrid.
SO THE PROBLEM IS:
I can't findcontrol for the org_id in the second datagrid.

The key issue here is the need to easily enable additional records to be
added to the second datagrid, to enable the registration of different orgs.

Anyone know about using multiple datagrids (not necessarily nested) on the
same page?
Just to prove I have NO idea what I'm doing, here's some of my code my code
(simplified)...

CODE SNIPPET
Private Sub user_profile_update(Sender As Object, E As
DataGridCommandEventArgs)
If page.isValid Then
Dim main_email As TextBox = e.Item.FindControl ("main_email")
Dim main_password As TextBox = e.Item.FindControl ("main_password")
Dim org_id As DropDownList = CType(FindControl ("org_id"), DropDownList)

data_set = load_user_data()

Dim data_table as String
data_table = "main_identity"
If data_set.tables(data_table).Rows.Count > 0 Then
With data_set.tables(data_table).Rows(0)
.Item("main_email") = main_email.Text
.Item("main_password") = main_password.Text
.Item("org_id") = org_id.selecteditem.value <<<<<< ERROR

ERROR
System.NullReferenceException: Object reference not set to an
instance of an object.

End With
End If

user_profile.EditItemIndex = -1
org_profile.EditItemIndex = -1
bind_profiles()
ViewState("Add") = "Off"
ViewState("Edit") = "Off"
End If
End Sub

<form runat="server" name="profile">

<ASP:DataGrid
id="user_profile"
runat="server"
Autogeneratecolumns="false"
MaintainState="false"
Border="0"
Cellspacing="0"
Cellpadding="0"
ShowFooter="true"
OnEditCommand="user_profile_edit"
OnCancelCommand="user_profile_cancel"
OnUpdateCommand="user_profile_update"
DataKeyField="main_id">
<Columns>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel"
UpdateText="Update" />
<asp:BoundColumn DataField="main_id" ReadOnly="True" visible="false"/>
<asp:TemplateColumn>
<ItemTemplate>
Email Address: <%# Container.DataItem("main_email") %
<br>
Password: <%# Container.DataItem("main_password") %
<br>
</ItemTemplate>
<EditItemTemplate>
Email Address: <asp:TextBox id="main_email" Size="7" Text='<%#
Container.DataItem("main_email") %>' runat="server"/><br>
Password: <asp:TextBox id="main_password" Size="7" Text='<%#
Container.DataItem("main_password") %>'
runat="server"/> said:
</EditItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:datagrid>

<ASP:DataGrid
id="org_profile"
runat="server"
Autogeneratecolumns="false"
MaintainState="false"
Border="0"
Cellspacing="0"
Cellpadding="0"
ShowFooter="false"
ShowHeader="false"
DataKeyField="org_id">
<Columns>
<asp:EditCommandColumn visible="false" EditText="Edit" CancelText="Cancel"
UpdateText="Update" />
<asp:BoundColumn DataField="org_id" ReadOnly="True" visible="false"/>
<asp:TemplateColumn>
<ItemTemplate>
Organization Name: <%# Container.DataItem
("org_name") %> said:
Organization Type: <%# Container.DataItem
("org_type_id") %> said:
</ItemTemplate>
<EditItemTemplate>
Organization Name:
<asp:dropDownList
id="org_id"
DataSource='<%#
load_dropdown_data
("organization_company","org_id","org_name","Other") %>'
 
Hi,

Thanks for the help!
I keep thinking about this issue, and I still am unclear about how to
structure my data and implement the form properly.
Let's start from scratch. Forget about what type of controls (two datagrids,
etc) I want to use, etc.

I have three tables, independent of each other.
Users, Orgs, Locs.

I want users to...

Register user data on the form.

Then

Choose from an existing Org.
OR
Register an Org.

Then

Choose an Org location (address, state, etc) associated to the org specified
or
Register an Org. location to be associated with the Org chosen

And I would like to do this on 1 form...

Please help! I am working hard but falling very far behind on this project !


Thanks!


Drew
NY
 
Hi,
Could you simplify your data structure by having two
tables - Users and Orgs, and just fit the location data
into columns in the Orgs table?
JT
-----Original Message-----
Hi,

Thanks for the help!
I keep thinking about this issue, and I still am unclear about how to
structure my data and implement the form properly.
Let's start from scratch. Forget about what type of controls (two datagrids,
etc) I want to use, etc.

I have three tables, independent of each other.
Users, Orgs, Locs.

I want users to...

Register user data on the form.

Then

Choose from an existing Org.
OR
Register an Org.

Then

Choose an Org location (address, state, etc) associated to the org specified
or
Register an Org. location to be associated with the Org chosen

And I would like to do this on 1 form...

Please help! I am working hard but falling very far behind on this project !


Thanks!


Drew
NY



"One Handed Man [ OHM ]" <terry_burnsREMOVE%FOR%NO% (e-mail address removed)>
wrote in message news:% (e-mail address removed)...
If I understand you correctly, you want to relate one datagrid to another
( Person )Master and ( Orgs ) Slave. scenario ?

If this is the case, you can define both tables in a
single dataset and
then
define the relationship between the two PK and FK.

Ok, now point the datasource of Grid one to the master and point the
datasource of the second to the relationship table2.relationshipname

This will link the two grids so clicking on the Person will give you the
related records in the second.


Regards OHM





the tables in the
bound
the first
user_profile
registration of different
orgs.
necessarily nested) on
the
some of my code my
code
("org_id"),
DropDownList)
reference not set to
an
EditText="Edit"
CancelText="Cancel"
("organization_company","org_id","org_name","Other")


.
 
Thank you for your reply.

I have switched to using TabStrip and I'm debating whether to use MultiPage
PageViews (preferred) or separate pages bound to TabStrip. In either case I
think your approach might work, but I'd rather have the complex data with
separate handling routines then create aliases and limit myself to a one to
one relationship. (maybe I'm just confused?)

In theory, the registration/profile manager I'm trying to build should only
display a one to one relationship at a time, but should allow for related
additions to each of the tables, with a slight modification to the script to
allow administration for moderation purposes. The idea behind using nested
or multiple DataGrids is to allow me to maintain one set of forms (with an
EditTemplate and ItemTemplate) for add new, edit, cancel. functionality
across all three tables without too much code. Now I think TabStrip will
allow me a great UI to do this but I'm still unclear about whether or not I
will run into the same problem as with multiple DataGrids / nested DataGrids
on the same form.

I ran into problems using FindControl for anything other then the first
table, since the EventArgs were not persisted through both datagrids. I have
not yet found a VB.net example of this that I understand.

So to summarize, I would like to have a tabbed registration page with the
first tab representing editable user information, the second tab
representing editable Org info, and the third tab representing Location
info, etc, etc...

I think I am in need of some instruction on building event handlers or
bubbling up events from the child DataGrid to the parent form, since I could
not get FindControl to work for the second DataGrid on one form. Anyone know
why? Is this by design or was I overlooking a different issue? I use an
update/SQL insertion routine using FindControl to post new/updated data to
SQL. I am assuming this is necessary.

Does anyone know if this is possible with TabStrip and multiple datagrids?

I already have a single DataGrid bound to a dataset (multiple tables, but
currently the DataGrid is only bound to the user table) with working form
elements, checkboxes, dropdown list, textbox, etc, as well as delete, edit,
AddNew, cancel, but that is the extent of my DotNet achievements, being a
VBScript man until a few weeks ago.

Does any of this make sense? Does anyone wanna see my code?

Drew
NY



JT said:
Hi,
Could you simplify your data structure by having two
tables - Users and Orgs, and just fit the location data
into columns in the Orgs table?
JT
-----Original Message-----
Hi,

Thanks for the help!
I keep thinking about this issue, and I still am unclear about how to
structure my data and implement the form properly.
Let's start from scratch. Forget about what type of controls (two datagrids,
etc) I want to use, etc.

I have three tables, independent of each other.
Users, Orgs, Locs.

I want users to...

Register user data on the form.

Then

Choose from an existing Org.
OR
Register an Org.

Then

Choose an Org location (address, state, etc) associated to the org specified
or
Register an Org. location to be associated with the Org chosen

And I would like to do this on 1 form...

Please help! I am working hard but falling very far behind on this project !


Thanks!


Drew
NY



"One Handed Man [ OHM ]" <terry_burnsREMOVE%FOR%NO% (e-mail address removed)>
wrote in message news:% (e-mail address removed)...
If I understand you correctly, you want to relate one datagrid to another
( Person )Master and ( Orgs ) Slave. scenario ?

If this is the case, you can define both tables in a
single dataset and
then
define the relationship between the two PK and FK.

Ok, now point the datasource of Grid one to the master and point the
datasource of the second to the relationship table2.relationshipname

This will link the two grids so clicking on the Person will give you the
related records in the second.


Regards OHM





I have the something like the following data structure:
Users
users_ID, orgs_ID, users_email, users_password, etc.
Orgs
orgs_ID, orgs_name, orgs_description, etc.

I have a single form with two datagrids.
I have loaded one dataset with two tables.
There is only a single record at any time in each of the tables in the
bound
dataset.
I bind the first datagrid to one datatable, and the second datagrid to
another datatable.

Both datagrids seem to populate just fine in edit mode, but...

My UPDATE routine is fired on the update command of
the first
user_profile
datagrid.
SO THE PROBLEM IS:
I can't findcontrol for the org_id in the second datagrid.

The key issue here is the need to easily enable additional records to be
added to the second datagrid, to enable the registration of different
orgs.

Anyone know about using multiple datagrids (not
necessarily nested) on
the
same page?
Just to prove I have NO idea what I'm doing, here's some of my code my
code
(simplified)...

CODE SNIPPET
Private Sub user_profile_update(Sender As Object, E As
DataGridCommandEventArgs)
If page.isValid Then
Dim main_email As TextBox = e.Item.FindControl ("main_email")
Dim main_password As TextBox = e.Item.FindControl ("main_password")
Dim org_id As DropDownList = CType(FindControl
("org_id"),
DropDownList)

data_set = load_user_data()

Dim data_table as String
data_table = "main_identity"
If data_set.tables(data_table).Rows.Count > 0 Then
With data_set.tables(data_table).Rows(0)
.Item("main_email") = main_email.Text
.Item("main_password") = main_password.Text
.Item("org_id") = org_id.selecteditem.value <<<<<< ERROR

ERROR
System.NullReferenceException: Object
reference not set to
an
instance of an object.

End With
End If

user_profile.EditItemIndex = -1
org_profile.EditItemIndex = -1
bind_profiles()
ViewState("Add") = "Off"
ViewState("Edit") = "Off"
End If
End Sub

<form runat="server" name="profile">

<ASP:DataGrid
id="user_profile"
runat="server"
Autogeneratecolumns="false"
MaintainState="false"
Border="0"
Cellspacing="0"
Cellpadding="0"
ShowFooter="true"
OnEditCommand="user_profile_edit"
OnCancelCommand="user_profile_cancel"
OnUpdateCommand="user_profile_update"
DataKeyField="main_id">
<Columns>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel"
UpdateText="Update" />
<asp:BoundColumn DataField="main_id" ReadOnly="True" visible="false"/>
<asp:TemplateColumn>
<ItemTemplate>
Email Address: <%# Container.DataItem
("main_email") %> said:
Password: <%# Container.DataItem("main_password")
%> said:
</ItemTemplate>
<EditItemTemplate>
Email Address: <asp:TextBox id="main_email" Size="7" Text='<%#
Container.DataItem("main_email") %>'
runat="server"/> said:
Password: <asp:TextBox id="main_password" Size="7" Text='<%#
Container.DataItem("main_password") %>'
runat="server"/> said:
</EditItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:datagrid>

<ASP:DataGrid
id="org_profile"
runat="server"
Autogeneratecolumns="false"
MaintainState="false"
Border="0"
Cellspacing="0"
Cellpadding="0"
ShowFooter="false"
ShowHeader="false"
DataKeyField="org_id">
<Columns>
<asp:EditCommandColumn visible="false" EditText="Edit"
CancelText="Cancel"
UpdateText="Update" />
<asp:BoundColumn DataField="org_id" ReadOnly="True" visible="false"/>
<asp:TemplateColumn>
<ItemTemplate>
Organization Name: <%# Container.DataItem
("org_name") %> said:
Organization Type: <%# Container.DataItem
("org_type_id") %> said:
</ItemTemplate>
<EditItemTemplate>
Organization Name:
<asp:dropDownList
id="org_id"
DataSource='<%#
load_dropdown_data
("organization_company","org_id","org_name","Other")
%>'
DataValueField="org_id"
DataTextField="org_name" runat="server"
SelectedValue = '<%# DataBinder.Eval (Container.DataItem,
"org_id")%>' />
</EditItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:datagrid>

</form>




Thanks!

Drew
ssoss


.
 
Back
Top