vendredi 2 janvier 2015

Cannot set value of ListView Item

I am having trouble setting the value of a textbox inside a nested listview (listview inside a lsitview). What I am trying to do is pull values of two textboxes (which is working fine), multiply them together, and set that value to the third textbox (where I am having the trouble).


here is the listview setup that I have:



<asp:ListView ID="LV_Tickets" runat="server" ClientIDMode="Static" DataSourceID="SQL_Tickets" InsertItemPosition="FirstItem" OnPreRender="LV_Tickets_PreRender" DataKeyNames="TicketNum">
<SelectedItemTemplate>

<asp:ListView ID="LV_TicketProd" runat="server" DataKeyNames="ChargeID" DataSourceID="SQL_TicketProducts" InsertItemPosition="LastItem" OnPreRender="LV_TicketProd_PreRender" OnItemInserted="LV_TicketProd_ItemInserted" OnItemInserting="LV_TicketProd_ItemInserting" OnItemUpdated="LV_TicketProd_ItemUpdated" OnItemUpdating="LV_TicketProd_ItemUpdating">
<InsertItemTemplate>

<td>
<asp:TextBox ID="HoursOrCubesTextBox" runat="server" style="height: 20px; width: 165px;" Text='<%# Bind("HoursOrCubes") %>' OnTextChanged="HoursOrCubes_TextChanged" AutoPostBack="true" />
</td>
<td>
<asp:TextBox ID="RateTextBox" runat="server" style="height: 20px; width: 120px;" Text='<%# Bind("Rate") %>' OnTextChanged="Rate_TextChanged" AutoPostBack="true" />
</td>
<td>
<asp:TextBox ID="LineTotalTextBox" runat="server" style="height: 20px; width: 120px;" Text='<%# Bind("LineTotal") %>' />
</td>

</ InsertItemTemplate>

</ SelectedItemTemplate>


The current way that I am getting the values from HoursOrCubesTextBox and RateTextBox is:



protected void HoursOrCubesTextBox_TextChanged(object sender, EventArgs e)
{
ListView LV_TicketProd = (ListView)Session["TicketProd"];
TextBox HoursOrCubesTextBox = (TextBox)(LV_TicketProd.InsertItem.FindControl("HoursOrCubesTextBox"));

string HoC = HoursOrCubesTextBox.Text //This here is getting the value from the textbox.
}


But when I try to do the opposite to set the value of the textbox nothing happens:



TextBox LineTotalTextBox = (TextBox)(LV_TicketProd.InsertItem.FindControl("LineTotalTextBox"));
LineTotalTextBox.Text = FinalValue; //FinalValue is the two values multiplied together.


I have check that the values coming from the textboxes are correct, and that when I multiply them together I get a value that is an integer. So I am not entirely sure why I cannot set the value of the LineTotalTextBox. Any help will be greatly appreciated.





Aucun commentaire:

Enregistrer un commentaire