bob white

bob white

  • NA
  • 13
  • 82.7k

update database via linq by iterating formcontrols ?

Jan 7 2011 6:46 PM

Hi, I need your help, here is my page code. my code suppose to capture the values form the textboxes and make the update to the DB.
background: I use a master page and my code is located in  web content form.
GUI interface contains labels and Text boxes. a user will fill the form upon making a selection from a dropdown list. Once the form is populated,
a user can edit the form, then click update to save changes. The problem is that although the user does not see any errors upon making the update.
NO updates are successfully done. I debuged the code and realized the following:
List<Control> inputControls = (from Control c in  this.Page.Form.Controls ... has a value of Zero . This means the code does not recognize the text.
Also, I do not know what is this code does:
this.Page.Form.Controls[11].Controls   // why .Controls[11].Controls
here is the code that is causing the issue:

I have 3 more fieldsets like the one below. Each contain a table with a couple of rows <TR> The content of the table rows
is like this one for all the <TR> content ( in all 3 fieldset ). GetValues() method is called  to capture the values and insert them
to the Database ....
Where is the trouble... I am not able to capture the controls of the form

<PRE>
<fieldset id="fldSubsidy">
<legend>Program Values <span class="edit">edit</span></legend>
<table width="100%">
      <tr>
            <td width="40%">
                  <label for="SubsidyRate" style="width: 16em;">
                        Subsidy Rate <i>(i.e 25.15% as 25.15)</i></label>
            </td>
            <td width="18%">
                  <asp:TextBox runat="server" ID="txtSubsidyRate" CssClass="isPercent" />
            </td>
            <td width="24%">
                  <div id="SubsidyRate" runat="server" />
            </td>
            <td width="18%">
                  <pre></pre>
            </td>
      </tr>
      <tr>
            <td>
                  <label>
                        Face Value Available to give</label>
            </td>
            <td>
                  <div id="FaceValAvailGive" runat="server" />
            </td>
            <td>
                  <asp:TextBox ID="txtFaceValAvailGive" runat="server" />
            </td>
            <td>
                  <pre></pre>
            </td>
      </tr>
</table>
</fieldset>
</PRE>
 
Here is the code behind
List
<Control> inputControls = (from Control c in this.Page.Form.Controls[11].Controls 
where c.GetType() == typeof(TextBox) select c).ToList();
List
<Control> divControls = (from Control c in this.Page.Form.Controls[11].Controls
where c.GetType() == typeof(HtmlGenericControl) &&
((
HtmlGenericControl)c).TagName == "div"
select c).ToList();
even when I change the code to this.Page.Form.Controls, it does not work,
I am not sure if the issue is in the front page (textbox tags) I appreciate your help and support.
Bob

Answers (1)