我有一个gridview,在gridview中我有一个名为yes的按钮..当我点击这个按钮时,Total amount textbox应该除以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)
{
}
答案 0 :(得分:1)
Try this Set CommandName as 'select' for the Button btnyes Add OnSelectedIndexChangedevent to gridview Clicking the btnyes will trigger OnSelectedIndexChangedevent event of the GeidView.
protected void Gridview2_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox txtboxtotal = (TextBox)Gridview2.SelectedRow.FindControl("txtboxtotal");
txtboxtotal.Text = (Convert.ToDecimal(txtboxtotal.Text) / 2).ToString();
}