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">
<ASPataGrid
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>
<ASPataGrid
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
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">
<ASPataGrid
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>
<ASPataGrid
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