如何计算两列并在Gridview中的另一列中获取结果 [英] How to Calculate two columns and get the result in another column in Gridview

查看:87
本文介绍了如何计算两列并在Gridview中的另一列中获取结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有gridView,因为我想将两列相乘(percentage * UserInput),结果应显示在列分数中.
该功能是当用户在文本框中的UserInput列中输入数字时,它将自动在成绩列中显示结果.

请帮帮我..
提前谢谢.


Hello Everyone,

I have gridView, in that i want to multiply two columns(percentage*UserInput) and the result should display in column score.
the functionality is when the user inputs a number in the textbox column UserInput, automatically it should display result in score column..

please help me..
Thanks in advance.


<asp:GridView ID="gVAppraisal" runat="server" AutoGenerateColumns="False" AllowPaging="True" CssClass="mGrid" PagerStyle-CssClass="pgr" " AlternatingRowStyle-CssClass="alt" EmptyDataText="No Results" PageSize="10" SelectedRowStyle-CssClass=" selectedRow" >
<Columns>
 <asp:BoundField DataField="Task" HeaderText="KRA" />
 <asp:BoundField DataField="Percentage" HeaderText=& quot;Weightage" />
 <asp:TemplateField HeaderText="UserInput">
  <ItemTemplate>
   <asp:TextBox ID="txtWeightage" runat="server" Width="40px"></asp:TextBox>
  </ItemTemplate>
 </asp:TemplateField>
 <asp:TemplateField HeaderText="Score">
  <ItemTemplate>
   <asp:Label ID="lblScore" runat="server" Text="0" ForeColor="Red"></asp:Label>
  </ItemTemplate>
 </asp:TemplateField>
 </Columns>
</asp:GridView>

推荐答案



请按照此操作.

1.设置第二个文本框的AutoPostBack属性.

2.处理第二个文本框的TextChanged事件.

3.以以下方式从GridView中访问第三个文本"框:
TextBox txtResult = GridView.Rows [((发送者为TextBox).NamingContainer为GridViewRow).Index] .Cells [2] .Controls [0];

txtResult.Text =在这里执行校准

希望这会对您有所帮助.
Hi,

Please follow this.

1. Set the AutoPostBack property for second text box.

2. Handle the TextChanged Event for Second text box.

3. Access the Third Text box from the GridView as

TextBox txtResult=GridView.Rows[((sender as TextBox).NamingContainer as GridViewRow).Index].Cells[2].Controls[0];

txtResult.Text= Here Perform the calclualations

Hope, this would help you.


尝试类似
的方法
try something like

<asp:TemplateField HeaderText="is">
    <ItemTemplate>
        <asp:Label Text="<%# int.Parse(percentage) * (decimal)Eval(txtWeightage.text)%>" runat="server" />
    </ItemTemplate>
</asp:TemplateField>


在gridview中

In gridview

<Columns>
 <asp:BoundField DataField="Task" HeaderText="KRA" />
 <asp:TemplateField HeaderText="Appraisal by Manager">
 <ItemTemplate>
 <asp:TextBox ID="txtPercentage" runat="server" Text='& lt;%#Eval("Percentage")%>' Width="40px"></asp:TextBox>
 </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Appraisal by Manager">
<ItemTemplate>
<asp:TextBox ID="txtW" runat="server" Width="40px" OnTextChanged="txtW_TextChanged" AutoPostBack="true"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Score">
<ItemTemplate>
<asp:TextBox ID="txtScore" runat="server" Text="0" Width="40px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>



和后面的代码...



and code behind...

protected void txtW_TextChanged(object sender, EventArgs e)
{
TextBox txtWeightage = (TextBox)gVAppraisal.Rows[((sender as TextBox).NamingContainer as GridViewRow).RowIndex].Cells[2].FindControl("txtW");
TextBox percentage = (TextBox)gVAppraisal.Rows[((sender as TextBox).NamingContainer as GridViewRow).RowIndex].Cells[2].FindControl("txtPercentage");
TextBox score = (TextBox)gVAppraisal.Rows[((sender as TextBox).NamingContainer as GridViewRow).RowIndex].Cells[2].FindControl("txtScore");       
score.Text = (Int32.Parse(percentage.Text) * (Int32.Parse(txtWeightage.Text))).ToString();
}



感谢Ragamayura,我在您的帮助下解决了这个问题.



Thanks to Ragamayura, i solved this issue with your help.


这篇关于如何计算两列并在Gridview中的另一列中获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆