Hi
I have a form view. Inside the formview I have a drop down. I did not bind the drop down with the ODS. Instead I do it manually on the code behind. If the user selects a value I display a textbox beside the drop down and allow the user to enter the value. Upon onblur event of the textbox I do a postback and in the page load i check whethere the page has been posted. If so I add this value to the datatable and once again bind it to the combo box and set the selected value to the text box value.
If the user clicks the save button and when I look for the selected value it says Nothing.
What could be the problem. Please help me in this regard.
Thanks a lot in advance.
![]() |
-1 |
![]() |
SelectedValue could be found on the same page. If there is a postback, it will be gone. Could you show your code?
![]() |
-1 |
![]() |
Please post your code so we can further assist you, but it seems that the value isn't being passed.
~~ Believe in Science, not religion. Science will always progress, religions will always collapse. ~~
![]() |
-1 |
![]() |
Try to user below code:
<asp:dropdownlist Id="1" Runat="Server" SelectedValue='<% Eval("Some data")%' DataTextField="Some Data Column" Sqldatasource="Sqldatasource1" />
I guess this will help you.
Here Selected value attribute will help you show the selected value of the user and datatext will help you show the dropdown data.....it may or may in your datasource dont bother about it
Thanks
Parth
visit for some interesting articals at
www.parthrawal.blogspot.com
Mark as Answer if it helps you
![]() |
-1 |
![]() |
In aspx page I have the following code
<asp:DropDownList ID="ddlSource" SkinID="DropDownNormalText" runat="server">
</asp:DropDownList>In the VB page I have
Page Load
ChangeFormViewModeByUserRole
If Me.IsPostBack And iTagID > ZERO Then
sValue = CType(Me.fvTags.FindControl("txtSource"), TextBox).Text
If (CType(Me.fvTags.FindControl("txtSource"), TextBox).Visible = True) AndAlso (sValue <> "") Then
Dim dt As DataTable = oTagNameMaintenance.GetTagSourcefromTags
AddRowToReturnTable(dt, sValue)
With CType(Me.fvTags.FindControl("ddlSource"), DropDownList)
.DataSource = dt
.DataBind()
.SelectedValue = sValue
End With
End If
CType(Me.fvTags.FindControl("txtSource"), TextBox).Text = ""End If
End Page load
Region Function
Private Sub AssignDataForSourceComboBox()
Dim dt As DataTable = oTagNameMaintenance.GetTagSourcefromTags
With CType(Me.fvTags.FindControl("ddlSource"), DropDownList)
.DataSource = dt
.DataTextField = "TagSource"
.DataValueField = "TagSource"
.DataBind()
End WithEnd Sub
Private Sub ChangeFormViewModeByUserRole()
If MasterPage.HasService("ReadWrite", sRedirectURL, oUser) Then
If iTagID > ZERO Then
fvTags.ChangeMode(FormViewMode.Edit)
AssignDataForSourceComboBox()
Me.pnlUserInfo.Visible = True
ElseIf iTagID = MINUS_ONE Then
fvTags.ChangeMode(FormViewMode.Insert)
AssignDataForSourceComboBox()
Me.pnlUserInfo.Visible = False
End If
Else
Me.lnkNew.Visible = False
If iTagID > ZERO Then
fvTags.ChangeMode(FormViewMode.ReadOnly)
Me.pnlUserInfo.Visible = True
CType(fvTags.FindControl("lnkExit"), HyperLink).NavigateUrl = sRedirectURL & "?ExpandResult=Y"
End If
End IfPrivate Sub odsTagDetails_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles odsTagDetails.Updating
e.InputParameters("TagSource") = CType(Me.fvTags.Row.FindControl("ddlSource"), DropDownList).SelectedValue
End Sub
While updating the ODS this is where I get the selected value for the drop down. I get Nothing here.
Please help me in this regard.
Thanks a lot for all your suggestions.
Thanks
Janakiraman
![]() |
1 |
![]() |
HI janakiraman ,
janakiraman:
Page Load
ChangeFormViewModeByUserRole
If Me.IsPostBack And iTagID > ZERO Then
sValue = CType(Me.fvTags.FindControl("txtSource"), TextBox).Text
If (CType(Me.fvTags.FindControl("txtSource"), TextBox).Visible = True) AndAlso (sValue <> "") Then
Dim dt As DataTable = oTagNameMaintenance.GetTagSourcefromTags
AddRowToReturnTable(dt, sValue)
With CType(Me.fvTags.FindControl("ddlSource"), DropDownList)
.DataSource = dt
.DataBind()
.SelectedValue = sValue
End With
End If
CType(Me.fvTags.FindControl("txtSource"), TextBox).Text = ""End If
End Page load
Please make sure you do not re-bind the DropDownlist before the method odsTagDetails_Updating execute , if ddl is rebound , the selectedvalue will be refreshed.
Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
![]() |
1 |
![]() |
Hi
Thanks a lot for all your response. What I have learnt from this is we should not bind data to the drop down upon post back. If so then we can't get the selected value. SO I changed my condition and bound the data ONLY when the page is loaded for the first time.
Thanks
Janakiraman
![]() |
-1 |
![]() |