DetailsView and template fields

  • Thread starter studio60podcast
  • Start date

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:
<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_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>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapter"
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>
 
Ad

Advertisements

C

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
 
S

studio60podcast

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!
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



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_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>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapter"
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>
 
C

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.

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!
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



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_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>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapter"
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>
 
S

studio60podcast

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
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.

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!
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



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_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>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapter"
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>
 
C

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

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
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.

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



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_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>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsInventoryItem" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetInventoryItemByID"
TypeName="dsItemTableAdapters.tbinv_itemTableAdapter"
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>
 
Ad

Advertisements

S

studio60podcast

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
 
Ad

Advertisements

C

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top