RE: DataGridView with databound combobox

Tech-Archive recommends: Fix windows errors by optimizing your registry



Thanks Phillip, I appreciate your effort!

1) I tried hard to get this working but one remaining stumblingblock is this
line:

<asp:DropDownList ID="cboActivityTime" runat="server"
DataSourceID="objTimes" DataValueField="TimeShow" DataTextField="TimeShow"
SelectedValue='<%# Bind("ActivityTime") %>' ></asp:DropDownList>

It will cause this error:
"'cboActivityTime' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value"

Possible workaoround?
Your solution obviously works. What is the difference? My ObjectDatasource
retrieves a DataView, will that be a problem?


2) And I am still VERY eager to manipulate the DropDownList in code behind
(Load, set SelectedValue, etc). I am much more used to plain code than these
ObjectSource objects, and find it more flexible.

In the GridView RowEditing Event I can easily get hold of the Literal
control of the TemplateField. Is it impossible to get hold of the
DropDownList control in a similar way?

<asp:TemplateField HeaderText="ActivityTime">
<ItemTemplate>
<asp:Literal ID="litActivityTime" runat="server"
Text='<%# Eval("ActivityTime") %>'></asp:Literal>
</ItemTemplate>
<EditItemTemplate>
<asp:ObjectDataSource ID="objTimes" runat="server"
TypeName="SKF.BusinessLogic.StaticInfo"
SelectMethod="GetNormalTimes"
DataObjectTypeName="SKF.BusinessLogic.StaticInfo"></asp:ObjectDataSource>
<asp:DropDownList ID="cboActivityTime" runat="server"
DataSourceID="objTimes" DataValueField="TimeShow" DataTextField="TimeShow"
SelectedValue='<%# Bind("ActivityTime") %>' ></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>


Protected Sub grdActivity_RowEditing(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewEditEventArgs) Handles
grdActivity.RowEditing
Dim grd As GridView
Dim row As GridViewRow
Dim lit As New Literal
Dim cbo As DropDownList

grd = DirectCast(sender, GridView)
row = DirectCast(sender, GridView).Rows(e.NewEditIndex)
lit = DirectCast(row.FindControl("litActivityTime"), Literal)
'cbo = DirectCast(row.FindControl("cboActivityTime"), DropDownList)
End Sub
.



Relevant Pages

  • .NET 2.0 Delete using GridView and ObjectDataSource
    ... connection) ... Dim list As New Generic.List ... the GridView has no DataKeyNames attribute set. ... DataObjectTypeName property in ObjectDataSource 'ObjectDataSource1'. ...
    (microsoft.public.dotnet.languages.vb)
  • Exporting to Excel directly from ObjectDataSource?
    ... I have a gridview with an objectdatasource. ... Dim tw As New IO.StringWriter ... Dim frm As HtmlForm = New HtmlForm ... I dislike that I have to pull from the Gridview at all. ...
    (microsoft.public.dotnet.framework.aspnet)
  • conditional formatting of text in a gridview
    ... I was looking to format the text of certain values in my gridview, ... If I don't use an ObjectDataSource - but instead manually populate the ... Dim strSBP As String = e.Row.Cells.Text ... Dim iSBP, iDBP, iSBPTarget, iDBPTarget As Integer ...
    (microsoft.public.dotnet.framework.aspnet)
  • Dynamically added user control
    ... I am dynamically adding a user control to each row in a gridview. ... ObjectDataSource) ... Dim pl As PlaceHolder = CType, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: dynamically building template columns
    ... getting added to the gridview, and my gridview gets pushed to the right. ... SortExpression before adding it to the gridview's Columns collection. ... Dim bfield As New BoundField ... // apply custom formatting to data cells ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)