Solved

ObjectDataSource retrieving column value

Posted on 2009-07-16
2
654 Views
Last Modified: 2012-05-07
Hi Guys,

I'm new to ASP.NET and wondering what the problem is with the following code. - see below. Basically what I have got is a FormView control which is getting it's data from a ObjectDataSource control. This all works fine. The ObjectDataSource uses a different source of data depending on the querystring (LocalPartnerID=...)

Now on my page load event, I call the method FindTypeEdit() in order to the value of one of my columns "Type" that has comma separated values like: Government, Non Government, International and pass it as a string to a method that will check if these selections are on the TypeCheckBoxList items choices to display them.

I'm using ObjectDataSource1.selectedparameters in hopes of accessing the values but well being not so familiar with ADO.NET I'm failing to select anything.
Please see below for my code

Many thanks in advance for your help!
Jeewai

ObjectDataSOurce connected to FormView:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="Delete" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}"     SelectMethod="GetDataLocalPartners"              TypeName="ICRSDataSetTableAdapters.tblLocalPartnerTableAdapter"
              UpdateMethod="Update">
              <DeleteParameters><asp:Parameter Name="Original_LocalPartnerID" Type="Byte" />
              </DeleteParameters>
              <UpdateParameters>   ...   </UpdateParameters>
              <SelectParameters> <asp:QueryStringParameter Name="LocalPartnerID"
                      QueryStringField="LocalPartnerID" Type="Byte" /> </SelectParameters>
              <InsertParameters>   ...    </InsertParameters>
          </asp:ObjectDataSource>
Public Sub FindTypeEdit()
        Dim TypeCheckBoxListEdit As CheckBoxList = CType(FormView1.FindControl("Tabcontainer1").FindControl("TabPanel1").FindControl("TypeCheckBoxListEdit"), CheckBoxList)
        'This was as a trial - hardcoded string of items -,representing possible values for the
        'column "Type" . This was to ensure that checkboxList items are passed and display ok
        'on CheckBoxList. 'Dim preferences As String = "Government,Non Government,International"
 
        'Now, in my real life senario, I need to get the value of column "Type"
        'and pass it as a string. This is where I fail.
        ObjectDataSource1.SelectParameters("Type").DefaultValue ' not working
        Dim preferences As String = ?????
 
        'The rest below works perfectly well provided I get string variables in my preference string
        Dim li As ListItem
        Dim preference() As String = preferences.Split(",")
        'Clear any previous setting
        TypeCheckBoxListEdit.SelectedIndex = -1
        For Each pref As String In preference
            li = TypeCheckBoxListEdit.Items.FindByValue(pref)
            If li Is Nothing = False Then
                li.Selected = True
            End If
        Next
    End Sub

Open in new window

0
Comment
Question by:jeewai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 200 total points
ID: 24879196
ObjectDataSource1.SelectParameters("Type").DefaultValue ' not working
Now Your ObjectDataSource1 does not have any Paramert Name "Type"..it has only one parameter defined:
<asp:QueryStringParameter Name="LocalPartnerID" QueryStringField="LocalPartnerID" Type="Byte" />

So I am not sure what you are trying to do....not getting any clear idea what is the exact problem.
0
 

Accepted Solution

by:
jeewai earned 0 total points
ID: 24885990
Thanks Guru_Sami for your comments,

Sorry for not being so clear in my post. What I wanted was simply to retrieve data from a certain column and pass it as a string. I have searched additional help in other forums and found out what to do:
create a hidden field inside my formview that is bound to that specific column,.. and simply pass the retrieved value as a string..

Jeewai

<asp:TextBox ID="HidTypeTextBoxEdit" runat="server" Visible="False" Text='<%# Bind("Type") %>'></asp:TextBox>



Public Sub FindTypeEdit()
Dim TypeCheckBoxListEdit As CheckBoxList = CType(FormView1.FindControl("Tabcontainer1").FindControl("TabPanel1").FindControl("TypeCheckBoxListEdit"), CheckBoxList)
'Get values from Hidden Type textField 
Dim HidTypeTextBoxEdit As TextBox = CType(FormView1.FindControl("Tabcontainer1").FindControl("TabPanel1").FindControl("HidTypeTextBoxEdit"), TextBox)
Dim preferences As String = HidTypeTextBoxEdit.Text
Dim li As ListItem
Dim preference() As String = preferences.Split(",")
'Clear any previous setting 
TypeCheckBoxListEdit.SelectedIndex = -1
li = TypeCheckBoxListEdit.Items.FindByValue(pref)
For Each pref As String In preferenceIf li Is Nothing = False Then 
li.Selected = True 
End If 
Next 
End Sub

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question