This is a migrated thread and some comments may be shown as answers.

Finding controls on FormView

2 Answers 48 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rich
Top achievements
Rank 1
Rich asked on 24 Jul 2012, 04:47 PM
I am having a problem getting the value of a field on a databound grid.

Here is the situation:
I have a Formview, that contains a Datagrid, that has a databound control.  I need to be able to get the value of that column so I can determine whether to do an insert or an update to a table.

Here is the definition of the Formview:
       <asp:FormView ID="FormView1" runat="server" DataSourceID="odsHeader" DefaultMode="Edit"
            Width="100%" DataKeyNames="SUBMITTAL_ID">

Here is the definition of the Grid:
      <rad:RadGrid ID="rgContactsDisplay" runat="server" AutoGenerateColumns="False" Skin="ABL_Std" GridLines="Both"
              DataSourceID="odsContacts" AllowMultiRowSelection="true"  Height="170px">
              <MasterTableView>
                     <Columns>
                          <rad:GridTemplateColumn UniqueName="grdCheckbox">
                                 <ItemTemplate>
                                       <asp:CheckBox ID= "chkContacts" runat="server" />
                          </rad:GridTemplateColumn>                                                                       </ItemTemplate>                                                                                                                                                                                                       
                          <rad:GridBoundColumn DataField="COMPANY_TYPE" UniqueName="company_Type" Visible="True" HeaderText="Company Type"
                                 <HeaderStyle Width="130px" />
                                        <ItemStyle Width="140px" />
                           </rad:GridBoundColumn>
                           <rad:GridBoundColumn DataField="COMPANY" HeaderText="Company" UniqueName="company" Visible="True"
                                  <HeaderStyle Width="140px" />
                                         <ItemStyle Width="140px" />
                           </rad:GridBoundColumn>
                           <rad:GridBoundColumn DataField="COMPANY_CONTACT_DATA" HeaderText="Contact" UniqueName="company_contact_data" Visible="True">
                                 <HeaderStyle Width="130px" />
                                      <ItemStyle Width="140px" />
                           </rad:GridBoundColumn>
                        <rad:GridBoundColumn DataField="CONTACTS_SOURCE" UniqueName="contacts_source" Visible="False" />
                        <rad:GridBoundColumn DataField="DOCUMENT_COMPANY_ID" UniqueName="document_company_id" Visible="False" />
          </Columns>

Here is what I have so far:
Dim grdContacts As RadGrid = CType(FormView1.FindControl("rgContactsDisplay"), RadGrid) //THIS LINE DOES GIVE ME A GRID OBJ
Dim grdSource As GridDataItem = CType(grdContacts.MasterTableView.FindControl("contacts_source"), GridDataItem)
//THIS LINE COMES UP WITH GRDSOURCE = NOTHING

What I need to be able to do is check the "contacts_source" field for a value so I can determine how to process.

Obviously I'm doing something wrong with the definition for grdSource, can anyone tell me what I need to do?

Many thanks in advance.

Rich

2 Answers, 1 is accepted

Sort by
0
Rich
Top achievements
Rank 1
answered on 24 Jul 2012, 05:23 PM
Was finally able to get there like so:
        Dim grdContacts As RadGrid = CType(FormView1.FindControl("rgContactsDisplay"), RadGrid)
        Dim grdSource As GridDataItem = CType(grdContacts.MasterTableView.Items(0), GridDataItem)

        Select Case grdSource.Item("contacts_source").Text
            Case "PRJ"
                'Insert logic here

            Case "SG"
                'Update logic here

        End Select
0
Anthony
Telerik team
answered on 24 Jul 2012, 05:30 PM
Hello Rich,

Glad to hear you found a solution. Let us know if you require further assistance.

Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Rich
Top achievements
Rank 1
Answers by
Rich
Top achievements
Rank 1
Anthony
Telerik team
Share this question
or