M
maurban
Hi there experts,
I have a gridview with a couple textboxes and a dropdownlist. I'm
trying to insert a default value into my database driven dropdownlist.
I'm doing this in the rowdatabound event. My problem is that my code
only works for the very first row in the gridview. For the first row,
when I press "edit", my gridview goes to edit mode, my textboxes and
dropdownlist populate. Further, my dropdownlist has the "Select" I
forced in as its default value.
If I try the 2nd row in my gridview, the dropdownlist populates,
however doesn't trigger the row databound command of inserting a
default value.
I tried going the "for each gridview row approach", and that just loops
for the number of rows I have. If I have two rows, it inserts the
default value "Select" twice in the dropdownlist for the first row
only. It still doesn't recognize any other row.
---- ASPX snippet ----
<EditItemTemplate>
<asp:dropdownlist ID="ddlUpdate_UserTypeID"
datavaluefield="user_type_id" datatextfield="user_type_desc"
DataSource='<%# Bind_ddlUserType() %>' Runat="server" />
</EditItemTemplate>
---- Code Behind snippet----
Sub gvUsers_rowDataBound(ByVal sender As Object, ByVal e As
GridViewRowEventArgs) _
Handles gvUsers.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow And _
e.Row.RowState = DataControlRowState.Edit Then
Dim user_id As String = e.Row.Cells(0).Text
CType(e.Row.FindControl("ddlUpdate_UserTypeID"),
DropDownList).Items.Insert(0, New ListItem("Select"))
End If
Please let me know if you require more detail. I've been spinning my
wheels on this for sometime now.
Thanks much for any assistance!
Mike
I have a gridview with a couple textboxes and a dropdownlist. I'm
trying to insert a default value into my database driven dropdownlist.
I'm doing this in the rowdatabound event. My problem is that my code
only works for the very first row in the gridview. For the first row,
when I press "edit", my gridview goes to edit mode, my textboxes and
dropdownlist populate. Further, my dropdownlist has the "Select" I
forced in as its default value.
If I try the 2nd row in my gridview, the dropdownlist populates,
however doesn't trigger the row databound command of inserting a
default value.
I tried going the "for each gridview row approach", and that just loops
for the number of rows I have. If I have two rows, it inserts the
default value "Select" twice in the dropdownlist for the first row
only. It still doesn't recognize any other row.
---- ASPX snippet ----
<EditItemTemplate>
<asp:dropdownlist ID="ddlUpdate_UserTypeID"
datavaluefield="user_type_id" datatextfield="user_type_desc"
DataSource='<%# Bind_ddlUserType() %>' Runat="server" />
</EditItemTemplate>
---- Code Behind snippet----
Sub gvUsers_rowDataBound(ByVal sender As Object, ByVal e As
GridViewRowEventArgs) _
Handles gvUsers.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow And _
e.Row.RowState = DataControlRowState.Edit Then
Dim user_id As String = e.Row.Cells(0).Text
CType(e.Row.FindControl("ddlUpdate_UserTypeID"),
DropDownList).Items.Insert(0, New ListItem("Select"))
End If
Please let me know if you require more detail. I've been spinning my
wheels on this for sometime now.
Thanks much for any assistance!
Mike