Last post Apr 18, 2007 11:18 AM by joker77
Apr 18, 2007 05:56 AM|joker77|LINK
I'm altering the Insert method of a DetailsView control, and would like to know how to get the values being inserted - i.e. what is displayed on screen in the BoundField
I have a NewItem.aspx page, which calls the method
public int Insert(Item x) to insert the record. Within here is where I'd like to know the values of the BoundFields
but can't seem to see how.
I've tried searching but you can't search just on the Blinq Preview forum which is a bit of a pain.
Apr 18, 2007 10:13 AM|jcrabtreesla|LINK
For each item as DetailsViewRow in yourDetailsView.Items
dim cell1 as TableCell = CType(item("YourColumnName"), TableCell)
dim value1 as string
value1 = cell1.Text
I used similar code to retreive items out of a grid, so I'm not 100% sure this will work correctly. You might need to mess with it a little to get the syntax right for a details view, but this should help. Also you will need to repeat the three lines in
the For Next block for each value from a different column you wish to retrieve. Hope that helps.
Apr 18, 2007 10:47 AM|joker77|LINK
I'm not sure how that would work, so instead I moved the code out of the Insert method of the PageDataSource, and into the ItemInserting event of the DetailsView. I can now get all the bound values by using the DetailsViewInsertEventArgs, e.g. string ContentName
However - I've no ran into another stumbling block. Along with the databound items for the table, I've added another DropDown listbox which is populated from another table. This isn't showing up in the DetailsViewInsertEventArgs - how do I get this value
- i.e. In the ItemInserting method of the DetailsView control, how do you get the value from a DropDown listbox that isn't bound?
Apr 18, 2007 11:18 AM|joker77|LINK
Thanks to jcrabtreesla for pointing me in the right direction!
I'll explain again the problem and how I got around it:
In my DetailsView control of a NewItem page, I have a BoundField called ContentName. Also in the DetailsView I have added a DropDownList of TopicIDs which is populated from another table called Topics, and I don't want this to form part of the Insert, so
after copying it in from another part of the code I removed the SelectedValue='<%# Bind("TopicID") %>', so it does not bind to the PageDateSource and is therefore not part of the Insert. I wanted to put some code in the Insert method of the PageDateSource,
but instead I put it in the ItemInserting method of the DetailsView control.
In the ItemInserting method of the DetailsView, I have added the following code to get the BoundField value of ContentName, and also the TopicID from the DropDownList:
string ContentName = e.Values["ContentName"].ToString();
// Get Value from DropDown
int TopicID = 0;
foreach (DetailsViewRow row in ItemsDetailsView.Rows)
if (row.Cells.Text == "Topic")
DropDownList TopicDropDown = (DropDownList)row.Cells.FindControl("Topic_TopicIDList");
TopicID = int.Parse(TopicDropDown.SelectedValue.ToString());