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

DetailsView and template fields

P: n/a
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:
<asp:DetailsView 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>
<asp:DropDownList ID="ddlPerson" runat="server"
CssClass="textGrey10" DataSourceID="odsInventoryPerson"
DataTextField="corp_person_fullname"
DataValueField="corp_person_id" Width="244px"
OnDataBound="ddlPerson_DataBound">
</asp:DropDownList>
<asp:ObjectDataSource ID="odsInventoryPerson" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetUndeletedPeople"
TypeName="dsPersonTableAdapters.tbcorp_personTable Adapter">
</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>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapt er"
UpdateMethod="UpdateItemByID" >
<UpdateParameters>
<asp:Parameter Name="corp_person_id" Type="Int32" />
<asp:Parameter Name="inv_item_description" Type="String" />
<asp:Parameter Name="inv_item_serial" Type="String" />
<asp:Parameter Name="inv_item_workauthorization" Type="String"
/>
<asp:Parameter Name="inv_item_purchasecost" Type="Single" />
<asp:Parameter Name="inv_item_podate" Type="DateTime" />
<asp:Parameter Name="inv_item_active" Type="Boolean" />
<asp:Parameter Name="inv_item_warrantyexpiration"
Type="DateTime" />
<asp:Parameter Name="inv_item_invoicenumber" Type="String" />
<asp:Parameter Name="inv_item_invoicedate" Type="DateTime" />
<asp:Parameter Name="Original_inv_item_id" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvItemList" Name="inv_item_id"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

Aug 7 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
CK
You need to specifiy the update method that will be used in your datasource
and you need some Control Update parameters. It would look something like
this.

<UpdateParameters>
<asp:ControlParameter ControlID="ddlPerson" PropertyName="SelectedValue"
Name="PersonID" />

</UpdateParameters>

Alternatively you could set the control parameter when you need it.
Something like this

ObjectDataSoure.UpdateParameters[0].value =
((DropDownList)dvEditItem.FindControl('ddlPerson') ).SelectedValue;

ObjectDataSource.Update();

Something like that should work for you. HTH.

~CK

<st*************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>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:
<asp:DetailsView 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>
<asp:DropDownList ID="ddlPerson" runat="server"
CssClass="textGrey10" DataSourceID="odsInventoryPerson"
DataTextField="corp_person_fullname"
DataValueField="corp_person_id" Width="244px"
OnDataBound="ddlPerson_DataBound">
</asp:DropDownList>
<asp:ObjectDataSource ID="odsInventoryPerson" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetUndeletedPeople"
TypeName="dsPersonTableAdapters.tbcorp_personTable Adapter">
</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>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapt er"
UpdateMethod="UpdateItemByID" >
<UpdateParameters>
<asp:Parameter Name="corp_person_id" Type="Int32" />
<asp:Parameter Name="inv_item_description" Type="String" />
<asp:Parameter Name="inv_item_serial" Type="String" />
<asp:Parameter Name="inv_item_workauthorization" Type="String"
/>
<asp:Parameter Name="inv_item_purchasecost" Type="Single" />
<asp:Parameter Name="inv_item_podate" Type="DateTime" />
<asp:Parameter Name="inv_item_active" Type="Boolean" />
<asp:Parameter Name="inv_item_warrantyexpiration"
Type="DateTime" />
<asp:Parameter Name="inv_item_invoicenumber" Type="String" />
<asp:Parameter Name="inv_item_invoicedate" Type="DateTime" />
<asp:Parameter Name="Original_inv_item_id" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvItemList" Name="inv_item_id"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

Aug 7 '06 #2

P: n/a
Thank you for the help. I didn't know how to access the Parameters
collection.

Some feedback though:
1. I do have an Update Method specified in the ObjectDataSource
definition. It's UpdateItemByID.
2. If I use your first suggesstion, I get an error stating that it
cannot find Control 'ddlPerson' in ControlParameter 'PersonID'
3. If I use your second suggestion, I don't find a "Value" property in
the UpdateParameters collection of the ObjectDataSource. I find
DefaultValue, but not Value.

Thanks!

CK wrote:
You need to specifiy the update method that will be used in your datasource
and you need some Control Update parameters. It would look something like
this.

<UpdateParameters>
<asp:ControlParameter ControlID="ddlPerson" PropertyName="SelectedValue"
Name="PersonID" />

</UpdateParameters>

Alternatively you could set the control parameter when you need it.
Something like this

ObjectDataSoure.UpdateParameters[0].value =
((DropDownList)dvEditItem.FindControl('ddlPerson') ).SelectedValue;

ObjectDataSource.Update();

Something like that should work for you. HTH.

~CK

<st*************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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:
<asp:DetailsView 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>
<asp:DropDownList ID="ddlPerson" runat="server"
CssClass="textGrey10" DataSourceID="odsInventoryPerson"
DataTextField="corp_person_fullname"
DataValueField="corp_person_id" Width="244px"
OnDataBound="ddlPerson_DataBound">
</asp:DropDownList>
<asp:ObjectDataSource ID="odsInventoryPerson" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetUndeletedPeople"
TypeName="dsPersonTableAdapters.tbcorp_personTable Adapter">
</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>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapt er"
UpdateMethod="UpdateItemByID" >
<UpdateParameters>
<asp:Parameter Name="corp_person_id" Type="Int32" />
<asp:Parameter Name="inv_item_description" Type="String" />
<asp:Parameter Name="inv_item_serial" Type="String" />
<asp:Parameter Name="inv_item_workauthorization" Type="String"
/>
<asp:Parameter Name="inv_item_purchasecost" Type="Single" />
<asp:Parameter Name="inv_item_podate" Type="DateTime" />
<asp:Parameter Name="inv_item_active" Type="Boolean" />
<asp:Parameter Name="inv_item_warrantyexpiration"
Type="DateTime" />
<asp:Parameter Name="inv_item_invoicenumber" Type="String" />
<asp:Parameter Name="inv_item_invoicedate" Type="DateTime" />
<asp:Parameter Name="Original_inv_item_id" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvItemList" Name="inv_item_id"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
Aug 7 '06 #3

P: n/a
CK
Assigning the default value to the desired value at run time should work. I
apologize I was answering that off the top of my head.

<st*************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Thank you for the help. I didn't know how to access the Parameters
collection.

Some feedback though:
1. I do have an Update Method specified in the ObjectDataSource
definition. It's UpdateItemByID.
2. If I use your first suggesstion, I get an error stating that it
cannot find Control 'ddlPerson' in ControlParameter 'PersonID'
3. If I use your second suggestion, I don't find a "Value" property in
the UpdateParameters collection of the ObjectDataSource. I find
DefaultValue, but not Value.

Thanks!

CK wrote:
>You need to specifiy the update method that will be used in your
datasource
and you need some Control Update parameters. It would look something like
this.

<UpdateParameters>
<asp:ControlParameter ControlID="ddlPerson" PropertyName="SelectedValue"
Name="PersonID" />

</UpdateParameters>

Alternatively you could set the control parameter when you need it.
Something like this

ObjectDataSoure.UpdateParameters[0].value =
((DropDownList)dvEditItem.FindControl('ddlPerson' )).SelectedValue;

ObjectDataSource.Update();

Something like that should work for you. HTH.

~CK

<st*************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googleg roups.com...
>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:
<asp:DetailsView 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>
<asp:DropDownList ID="ddlPerson" runat="server"
CssClass="textGrey10" DataSourceID="odsInventoryPerson"
DataTextField="corp_person_fullname"
DataValueField="corp_person_id" Width="244px"
OnDataBound="ddlPerson_DataBound">
</asp:DropDownList>
<asp:ObjectDataSource ID="odsInventoryPerson" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetUndeletedPeople"
TypeName="dsPersonTableAdapters.tbcorp_personTable Adapter">
</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>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapt er"
UpdateMethod="UpdateItemByID" >
<UpdateParameters>
<asp:Parameter Name="corp_person_id" Type="Int32" />
<asp:Parameter Name="inv_item_description" Type="String" />
<asp:Parameter Name="inv_item_serial" Type="String" />
<asp:Parameter Name="inv_item_workauthorization" Type="String"
/>
<asp:Parameter Name="inv_item_purchasecost" Type="Single" />
<asp:Parameter Name="inv_item_podate" Type="DateTime" />
<asp:Parameter Name="inv_item_active" Type="Boolean" />
<asp:Parameter Name="inv_item_warrantyexpiration"
Type="DateTime" />
<asp:Parameter Name="inv_item_invoicenumber" Type="String" />
<asp:Parameter Name="inv_item_invoicedate" Type="DateTime" />
<asp:Parameter Name="Original_inv_item_id" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvItemList" Name="inv_item_id"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

Aug 7 '06 #4

P: n/a
Sorry, I meant to include this in the last post, but when I assign the
DefaultValue, it works on the first try, but not on subsequent updates.
For example:
If I edit item 1, assigning DefaultValue works. If I try to edit item
1 again, it doesn't work.
But, if after editing item 1 I edit item 2, that works and going back
to item 1 works as well. It's like it won't work twice in a row...

Any thoughts?

Thanks!
Jason

CK wrote:
Assigning the default value to the desired value at run time should work. I
apologize I was answering that off the top of my head.

<st*************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Thank you for the help. I didn't know how to access the Parameters
collection.

Some feedback though:
1. I do have an Update Method specified in the ObjectDataSource
definition. It's UpdateItemByID.
2. If I use your first suggesstion, I get an error stating that it
cannot find Control 'ddlPerson' in ControlParameter 'PersonID'
3. If I use your second suggestion, I don't find a "Value" property in
the UpdateParameters collection of the ObjectDataSource. I find
DefaultValue, but not Value.

Thanks!

CK wrote:
You need to specifiy the update method that will be used in your
datasource
and you need some Control Update parameters. It would look something like
this.

<UpdateParameters>
<asp:ControlParameter ControlID="ddlPerson" PropertyName="SelectedValue"
Name="PersonID" />

</UpdateParameters>

Alternatively you could set the control parameter when you need it.
Something like this

ObjectDataSoure.UpdateParameters[0].value =
((DropDownList)dvEditItem.FindControl('ddlPerson') ).SelectedValue;

ObjectDataSource.Update();

Something like that should work for you. HTH.

~CK

<st*************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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:
<asp:DetailsView 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>
<asp:DropDownList ID="ddlPerson" runat="server"
CssClass="textGrey10" DataSourceID="odsInventoryPerson"
DataTextField="corp_person_fullname"
DataValueField="corp_person_id" Width="244px"
OnDataBound="ddlPerson_DataBound">
</asp:DropDownList>
<asp:ObjectDataSource ID="odsInventoryPerson" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetUndeletedPeople"
TypeName="dsPersonTableAdapters.tbcorp_personTable Adapter">
</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>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapt er"
UpdateMethod="UpdateItemByID" >
<UpdateParameters>
<asp:Parameter Name="corp_person_id" Type="Int32" />
<asp:Parameter Name="inv_item_description" Type="String" />
<asp:Parameter Name="inv_item_serial" Type="String" />
<asp:Parameter Name="inv_item_workauthorization" Type="String"
/>
<asp:Parameter Name="inv_item_purchasecost" Type="Single" />
<asp:Parameter Name="inv_item_podate" Type="DateTime" />
<asp:Parameter Name="inv_item_active" Type="Boolean" />
<asp:Parameter Name="inv_item_warrantyexpiration"
Type="DateTime" />
<asp:Parameter Name="inv_item_invoicenumber" Type="String" />
<asp:Parameter Name="inv_item_invoicedate" Type="DateTime" />
<asp:Parameter Name="Original_inv_item_id" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvItemList" Name="inv_item_id"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
Aug 7 '06 #5

P: n/a
CK
try a function that returns the desired value. Like

public string getDDLvalue()
{
return
((DropDownList)dvEditItem.FindControl('ddlPerson') ).SelectedValue;
}

then try
ObjectDataSoure.UpdateParameters[0].value = getDDLValue();

Maybe that will work better for you. I am not sure.
~CK

<st*************@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Sorry, I meant to include this in the last post, but when I assign the
DefaultValue, it works on the first try, but not on subsequent updates.
For example:
If I edit item 1, assigning DefaultValue works. If I try to edit item
1 again, it doesn't work.
But, if after editing item 1 I edit item 2, that works and going back
to item 1 works as well. It's like it won't work twice in a row...

Any thoughts?

Thanks!
Jason

CK wrote:
>Assigning the default value to the desired value at run time should work.
I
apologize I was answering that off the top of my head.

<st*************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googleg roups.com...
Thank you for the help. I didn't know how to access the Parameters
collection.

Some feedback though:
1. I do have an Update Method specified in the ObjectDataSource
definition. It's UpdateItemByID.
2. If I use your first suggesstion, I get an error stating that it
cannot find Control 'ddlPerson' in ControlParameter 'PersonID'
3. If I use your second suggestion, I don't find a "Value" property in
the UpdateParameters collection of the ObjectDataSource. I find
DefaultValue, but not Value.

Thanks!

CK wrote:
You need to specifiy the update method that will be used in your
datasource
and you need some Control Update parameters. It would look something
like
this.

<UpdateParameters>
<asp:ControlParameter ControlID="ddlPerson"
PropertyName="SelectedValue"
Name="PersonID" />

</UpdateParameters>

Alternatively you could set the control parameter when you need it.
Something like this

ObjectDataSoure.UpdateParameters[0].value =
((DropDownList)dvEditItem.FindControl('ddlPerson' )).SelectedValue;

ObjectDataSource.Update();

Something like that should work for you. HTH.

~CK

<st*************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googleg roups.com...
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:
<asp:DetailsView 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>
<asp:DropDownList ID="ddlPerson" runat="server"
CssClass="textGrey10" DataSourceID="odsInventoryPerson"
DataTextField="corp_person_fullname"
DataValueField="corp_person_id" Width="244px"
OnDataBound="ddlPerson_DataBound">
</asp:DropDownList>
<asp:ObjectDataSource ID="odsInventoryPerson" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetUndeletedPeople"
TypeName="dsPersonTableAdapters.tbcorp_personTable Adapter">
</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>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapt er"
UpdateMethod="UpdateItemByID" >
<UpdateParameters>
<asp:Parameter Name="corp_person_id" Type="Int32" />
<asp:Parameter Name="inv_item_description" Type="String" />
<asp:Parameter Name="inv_item_serial" Type="String" />
<asp:Parameter Name="inv_item_workauthorization" Type="String"
/>
<asp:Parameter Name="inv_item_purchasecost" Type="Single" />
<asp:Parameter Name="inv_item_podate" Type="DateTime" />
<asp:Parameter Name="inv_item_active" Type="Boolean" />
<asp:Parameter Name="inv_item_warrantyexpiration"
Type="DateTime" />
<asp:Parameter Name="inv_item_invoicenumber" Type="String" />
<asp:Parameter Name="inv_item_invoicedate" Type="DateTime" />
<asp:Parameter Name="Original_inv_item_id" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvItemList" Name="inv_item_id"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>


Aug 7 '06 #6

P: n/a
That didn't work.

I'll keep looking, but thank you for your help! If you do think of
something else, though, let me know.

Jason

Aug 7 '06 #7

P: n/a
CK
When are you trying to retreive and set the value?
Try it in the ObjectDataSource1_Updating event. You'll need to register that
event. Probably like in the PageLoad event
Try retrieving and setting the value in that event maybe. Sorry i wish i
could help you more.

<st*************@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
That didn't work.

I'll keep looking, but thank you for your help! If you do think of
something else, though, let me know.

Jason

Aug 7 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.