bob white

bob white

  • NA
  • 13
  • 99.9k

insert via Linq is not working

Jan 4 2011 4:21 PM

Hi,
I am trying to fix this page in aspx 3.5 , C# . The code is in Linq and does not insert the values from the form.
I have about 20 fields to be updated in a single aspx page, whoever developed this page did the following:
divided the page into  4 sections, each section has its own edit hyperlinked button to put the section in edit mode( for all 4 sections) a user can make a selection from drop down list to filter the requested records from the DB, then once the form is populated, a user can click any edit hyperlink ( in one of the four sections above ). however, when I run it , it does not make update to the table.   Here is some code  . I never worked with Linq, so your help is apprecited.... why it is not making the update when I call the stored procedure.. I have used the debuger and find out that  this method does not capture the values from the GUI ... private Dictionary<String, String> GetValues() {.... see full method below} what I ment, is when I run the deguger  and when it test    if(inputControls.Count >0 ) .. it skip it and the code inside the if statement never executed, this tells me that the GetValues() method does not fill the iput control and that is what I need to understand why it is not capturing the values???   thanks Bob
<tr>
<td><label>Maturity Date</label></td>
<td><asp:TextBox runat="server" id="txtMaturityDate" CssClass="isDate" /></td>
<td><div id="MaturityDate" runat="server" /></td>
<td><pre></pre></td>
</tr>
 
Most of the aspx page contains label, sever control, div tag with runat="server" (not sure why it is there??)  and <pre> tag
 this is part of the code behind  , it does not capture the values from the GUI ??
protected void btnSaveData_Click(object sender, EventArgs e)
{
#region No longer Used
Dictionary<String, String> values = GetValues();
if (values != null && values.Count > 0)
{
int? retVal = apporBL.SubmitApportionmentValues(ddlAslProgram.SelectedValue,
Convert.ToInt32(ddlCohort.SelectedValue), Convert.ToInt32(ddlFiscalYear.SelectedValue),
values);
if (retVal != null || retVal != 0)
{
//lbAssocBudgets.Items.Clear();
#region Reset Values
ResetHtmlControls();
//foreach ( TextBox t in inputControls )
//{
// t.Text = String.Empty;
//}
lblError.Visible = true;
lblError.Text = "Data successfully submitted!!!!";
#endregion
btnSubmitFilter_Click(this, new EventArgs());
}
}
#endregion
}
#region Helper Methods
/// <summary>
/// Retrieve the Values from the UI
/// </summary>
/// <returns>Key/Value pairs for all the input controls within div.valueContainer </returns>
private Dictionary<String, String> GetValues()
{
List<Control> inputControls = (from Control c in this.Page.Form.Controls[11].Controls
where c.GetType() == typeof(TextBox)// && !String.IsNullOrEmpty( ( (TextBox)c ).Text )
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();
Dictionary<string, string> values = new Dictionary<string, string>();
if (inputControls.Count > 0)
{
int i = 0;
foreach (TextBox t in inputControls)
{
// Ignore TextBoxes that have the class "calculatedField"
if (t.CssClass != "calculatedField")
{
// Stores the new Value in to the Array
if (!String.IsNullOrEmpty(t.Text))
{
values.Add(t.ID, t.Text);
}
else
{
// Takes the Old value and stores it into the Array
values.Add(t.ID, ((HtmlGenericControl)divControls[i]).InnerText);
}
}
else
{
// Although we ignore, we still need to pass
// a KVP to the Business Layer
values.Add(t.ID, String.Empty);
}
i++;
}
}
return values;
}