2014-01-05 16 views
1
<asp:GridView ID="GVFeedType" runat="server" Style="margin-bottom: 6px" BorderColor="#BDBDBD" 
    CssClass="center" Width="500px" AutoGenerateColumns="false"> 
    <EmptyDataTemplate> 
     No Records found</EmptyDataTemplate> 
    <Columns> 
     <asp:BoundField HeaderText="SNo" DataField="SNo" ItemStyle-Width="50px" /> 
     <asp:BoundField HeaderText="Feed Type" DataField="FeedType" ItemStyle-Width="200px" /> 
     <asp:TemplateField HeaderText="Rate/Kg" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center"> 
      <ItemTemplate> 
       <asp:TextBox ID="txtrate" runat="server" Width="100px" OnTextChanged="txtrate_TextChanged" 
        AutoPostBack="true" /> 
       <asp:RequiredFieldValidator ID="RFVrecdate1" runat="server" ControlToValidate="txtrate" 
        Display="None" ErrorMessage="Must Enter Rate" ValidationGroup="duereport"></asp:RequiredFieldValidator> 

      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Rate/50 Kg" ItemStyle-Width="80px"> 
      <ItemTemplate> 
       <asp:Label ID="lbl50kg" runat="server" /> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

我想這個代碼..如何使用javascript來增加文本框的值?

protected void txtrate_TextChanged(object sender, EventArgs e) 
{ 

    GridViewRow currentRow = (GridViewRow)(sender as TextBox).Parent.Parent; 
    float rate = 0; 
    float kgrate50 = 50; 

    rate = Convert.ToSingle((sender as TextBox).Text.Trim()); 
    kgrate50 = rate * kgrate50; 
    (currentRow.Cells[3].FindControl("lbl50kg") as Label).Text = kgrate50.ToString(); 
    GVFeedType.Rows[currentRow.RowIndex + 1].Cells[2].FindControl("txtrate").Focus(); 
} 

此代碼是好的,標籤不工作... 我有一個網格視圖控件的文本框,當我輸入一些值像2,3, 4 ..然後它乘以50 ...它顯示輸出在標籤控制..這裏標籤也在一個gridview ..我可以解決它..請幫助我..

回答

0

我會添加CSs類文本框

<asp:TextBox ID="txtrate" runat="server" CssClass="TextBoxToHandle" Width="100px" OnTextChanged="txtrate_TextChanged" 
        AutoPostBack="true" /> 

由於使用標籤投擲聚焦事件,您需要訂閱它

$(function(){ 
    $(".TextBoxToHandle").focusout(function(){ 
    //Do your code here this would be element which you focus left 
    }); 
}) 
相關問題