0

我有一个gridview,在gridview中我有一个名为yes的按钮..当我单击此按钮时,总金额文本框应除以2,答案应显示在同一个文本框中..我创建了一个名为的事件划分...但我不知道如何进一步编码..请有人帮我..下面是我的代码

<asp:GridView ID="Gridview2" runat="server" 
    AutoGenerateColumns="false" CellPadding="4" CssClass="vutblrow" 
    ForeColor="#333333" GridLines="None" HeaderStyle-CssClass="vutblhdr" 
    Height="16px" onrowcreated="Gridview2_RowCreated" 
    onrowdatabound="grvCalc_RowDataBound" PagerStyle-Mode="NumericPages" 
    ShowFooter="true" TabIndex="3" Width="1%">
    <PagerStyle BorderStyle="Solid" CssClass="pgr" Height="25px" />
        <Columns>
            <asp:BoundField DataField="RowNumber" HeaderText="Serial Number" />
            <asp:TemplateField HeaderText="From Place">
                <ItemTemplate>
                    <asp:TextBox ID="Textfrom" runat="server" CssClass="txtBoxNormalmedium"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="To Place">
                <ItemTemplate>
                    <asp:TextBox ID="Textto" runat="server" 
CssClass="txtBoxNormalmedium"></asp:TextBox>
                </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="Distance Travelled (kms)">
                 <ItemTemplate>
                    <asp:TextBox ID="TextBoxdist" runat="server" CssClass="txtBoxNormalmedium"></asp:TextBox>
                 </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField HeaderText="Amount Paid (per km)">
                  <ItemTemplate>
                       <asp:TextBox ID="TextBoxamt" runat="server" CssClass="txtBoxNormalmedium"></asp:TextBox>
                   </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="Conveyance Shared?">
                    <ItemTemplate>
                        <asp:Button ID="btnyes" Text="Yes" runat="server" CssClass="btnNormal" OnClick="divide" />
                    </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="Total amount">
               <ItemTemplate>
                    <asp:TextBox ID="txtboxtotal" runat="server" 
                        CssClass="txtBoxNormalmedium"></asp:TextBox>
                </ItemTemplate>
                <FooterStyle HorizontalAlign="Right" />
                <FooterTemplate>
                    <asp:Label ID="lbltotal" runat="server"></asp:Label>
                    <asp:Button ID="ButtonAdd1" runat="server" CssClass="btnNormalAdd" OnClick="add" Text="Add New Row" />
                    <asp:Button ID="btnok3" runat="server" CssClass="btnNormalAdd" OnClick="ok_click" Text="OK" />
                 </FooterTemplate>
              </asp:TemplateField>
              <asp:TemplateField>
                   <ItemTemplate>
                        <asp:LinkButton ID="LinkButton2" runat="server" CssClass="lnkbut" OnClick="LinkButton2_Click">Remove</asp:LinkButton>
                   </ItemTemplate>
              </asp:TemplateField>
          </Columns>
     </asp:GridView>


    protected void divide(object sender, EventArgs e)
            {

            }
4

1 回答 1

1
尝试这个

将按钮 btnyes 的 CommandName 设置为“选择”
将 OnSelectedIndexChangedevent 添加到 gridview
点击 btnyes 将触发 GeidView 的 OnSelectedIndexChangedevent 事件。
protected void Gridview2_SelectedIndexChanged(object sender, EventArgs e)
{
    TextBox txtboxtotal = (TextBox)Gridview2.SelectedRow.FindControl("txtboxtotal");
    txtboxtotal.Text = (Convert.ToDecimal(txtboxtotal.Text) / 2).ToString();
}
于 2013-11-07T20:56:23.943 回答