S
studio60podcast
I have a gridview and a details view in a page. The two are hooked up,
so that when a row is selected in the GridView, the DetailsView
displays the details. But, what I'm trying to accomplish is this:
I have two tables - user and item.
user table:
user_id int
user_name varchar(50)
item table:
item_id int
user_id int (foreign key from user table)
item_name varchar(50)
The item table contains inventory items and it has a foreign key from
the user table indicating which user posseses that inventory. However,
when editing this item, if I need to change the user to whom it is
assigned, I want to display the user's name rather than the users id
from the item table in a DropDownList in the DetailsView. So what I
have done to accomplish this is create a TemplateField that holds a
DropDownList and an ObjectDataSource that populates the DDL with all of
the possible users. And in the DataBound event, I select the user's
name in the DDL to whom the item is currently assigned. But I don't
know how to capture the selected user'd id and pass it to the Update
method in the ObjectDataSource for the DetailsView. I hope this has
been clear...
Here is some code:
<aspetailsView ID="dvEditItem" runat="server" Height="50px"
GridLines="None" AutoGenerateRows="False" DataKeyNames="inv_item_id"
DataSourceID="odsInventoryItem" DefaultMode="Edit"
OnItemUpdated="dvEditItem_ItemUpdated" >
<Fields>
<asp:TemplateField HeaderText="User"
SortExpression="inv_person_id">
<EditItemTemplate>
<aspropDownList ID="ddlPerson" runat="server"
CssClass="textGrey10" DataSourceID="odsInventoryPerson"
DataTextField="corp_person_fullname"
DataValueField="corp_person_id" Width="244px"
OnDataBound="ddlPerson_DataBound">
</aspropDownList>
<asp:ObjectDataSource ID="odsInventoryPerson" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetUndeletedPeople"
TypeName="dsPersonTableAdapters.tbcorp_personTableAdapter">
</asp:ObjectDataSource>
</EditItemTemplate>
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:TemplateField>
<asp:BoundField DataField="inv_item_description"
HeaderText="Description" SortExpression="inv_item_description">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_serial" HeaderText="Serial
Number" SortExpression="inv_item_serial">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_workauthorization"
HeaderText="Work Authorization"
SortExpression="inv_item_workauthorization">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_purchasecost"
HeaderText="Purchase Cost" SortExpression="inv_item_purchasecost">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_podate" HeaderText="PO Date"
SortExpression="inv_item_podate">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_warrantyexpiration"
HeaderText="Warranty Expires"
SortExpression="inv_item_warrantyexpiration">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_invoicenumber"
HeaderText="Invoice Number" SortExpression="inv_item_invoicenumber">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_invoicedate"
HeaderText="Invoice Date" SortExpression="inv_item_invoicedate">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:CheckBoxField DataField="inv_item_active"
HeaderText="Active" SortExpression="inv_item_active">
<ItemStyle HorizontalAlign="Left" Width="50px" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:CheckBoxField>
<asp:CommandField ButtonType="Button" ShowCancelButton="False"
ShowEditButton="True">
<ControlStyle CssClass="textGrey10" />
</asp:CommandField>
</Fields>
</aspetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapter"
UpdateMethod="UpdateItemByID" >
<UpdateParameters>
<asparameter Name="corp_person_id" Type="Int32" />
<asparameter Name="inv_item_description" Type="String" />
<asparameter Name="inv_item_serial" Type="String" />
<asparameter Name="inv_item_workauthorization" Type="String"
/>
<asparameter Name="inv_item_purchasecost" Type="Single" />
<asparameter Name="inv_item_podate" Type="DateTime" />
<asparameter Name="inv_item_active" Type="Boolean" />
<asparameter Name="inv_item_warrantyexpiration"
Type="DateTime" />
<asparameter Name="inv_item_invoicenumber" Type="String" />
<asparameter Name="inv_item_invoicedate" Type="DateTime" />
<asparameter Name="Original_inv_item_id" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvItemList" Name="inv_item_id"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
so that when a row is selected in the GridView, the DetailsView
displays the details. But, what I'm trying to accomplish is this:
I have two tables - user and item.
user table:
user_id int
user_name varchar(50)
item table:
item_id int
user_id int (foreign key from user table)
item_name varchar(50)
The item table contains inventory items and it has a foreign key from
the user table indicating which user posseses that inventory. However,
when editing this item, if I need to change the user to whom it is
assigned, I want to display the user's name rather than the users id
from the item table in a DropDownList in the DetailsView. So what I
have done to accomplish this is create a TemplateField that holds a
DropDownList and an ObjectDataSource that populates the DDL with all of
the possible users. And in the DataBound event, I select the user's
name in the DDL to whom the item is currently assigned. But I don't
know how to capture the selected user'd id and pass it to the Update
method in the ObjectDataSource for the DetailsView. I hope this has
been clear...
Here is some code:
<aspetailsView ID="dvEditItem" runat="server" Height="50px"
GridLines="None" AutoGenerateRows="False" DataKeyNames="inv_item_id"
DataSourceID="odsInventoryItem" DefaultMode="Edit"
OnItemUpdated="dvEditItem_ItemUpdated" >
<Fields>
<asp:TemplateField HeaderText="User"
SortExpression="inv_person_id">
<EditItemTemplate>
<aspropDownList ID="ddlPerson" runat="server"
CssClass="textGrey10" DataSourceID="odsInventoryPerson"
DataTextField="corp_person_fullname"
DataValueField="corp_person_id" Width="244px"
OnDataBound="ddlPerson_DataBound">
</aspropDownList>
<asp:ObjectDataSource ID="odsInventoryPerson" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetUndeletedPeople"
TypeName="dsPersonTableAdapters.tbcorp_personTableAdapter">
</asp:ObjectDataSource>
</EditItemTemplate>
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:TemplateField>
<asp:BoundField DataField="inv_item_description"
HeaderText="Description" SortExpression="inv_item_description">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_serial" HeaderText="Serial
Number" SortExpression="inv_item_serial">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_workauthorization"
HeaderText="Work Authorization"
SortExpression="inv_item_workauthorization">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_purchasecost"
HeaderText="Purchase Cost" SortExpression="inv_item_purchasecost">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_podate" HeaderText="PO Date"
SortExpression="inv_item_podate">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_warrantyexpiration"
HeaderText="Warranty Expires"
SortExpression="inv_item_warrantyexpiration">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_invoicenumber"
HeaderText="Invoice Number" SortExpression="inv_item_invoicenumber">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:BoundField DataField="inv_item_invoicedate"
HeaderText="Invoice Date" SortExpression="inv_item_invoicedate">
<ControlStyle CssClass="detailsViewControlSmall" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:BoundField>
<asp:CheckBoxField DataField="inv_item_active"
HeaderText="Active" SortExpression="inv_item_active">
<ItemStyle HorizontalAlign="Left" Width="50px" />
<HeaderStyle CssClass="detailsViewHeaderText" />
</asp:CheckBoxField>
<asp:CommandField ButtonType="Button" ShowCancelButton="False"
ShowEditButton="True">
<ControlStyle CssClass="textGrey10" />
</asp:CommandField>
</Fields>
</aspetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapter"
UpdateMethod="UpdateItemByID" >
<UpdateParameters>
<asparameter Name="corp_person_id" Type="Int32" />
<asparameter Name="inv_item_description" Type="String" />
<asparameter Name="inv_item_serial" Type="String" />
<asparameter Name="inv_item_workauthorization" Type="String"
/>
<asparameter Name="inv_item_purchasecost" Type="Single" />
<asparameter Name="inv_item_podate" Type="DateTime" />
<asparameter Name="inv_item_active" Type="Boolean" />
<asparameter Name="inv_item_warrantyexpiration"
Type="DateTime" />
<asparameter Name="inv_item_invoicenumber" Type="String" />
<asparameter Name="inv_item_invoicedate" Type="DateTime" />
<asparameter Name="Original_inv_item_id" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvItemList" Name="inv_item_id"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>