Click here to Skip to main content
14,826,929 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
sir, i have a gridview in which i have 3 column:- ID,Number,Amount.

<asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="false"  DataKeyNames="ID">

                          <asp:TemplateField Visible="false">
                                  <asp:Label ID="LblFeeHeadOther" runat="server" Text='<%# Bind("ID") %>'></asp:Label>

              <asp:TemplateField SortExpression="Amount" HeaderText="n(Amount)"  HeaderStyle-Width="70px">
                                  <asp:DropDownList ID="DdlMultiply" runat="server"   AutoPostBack="true"   OnSelectedIndexChanged="Multiply">
                                  <asp:ListItem Value="1">1</asp:ListItem>
                                  <asp:ListItem Value="2">2</asp:ListItem>
                                  <asp:ListItem Value="3">3</asp:ListItem>
                                  <asp:ListItem Value="4">4</asp:ListItem>
                                  <asp:ListItem Value="5">5</asp:ListItem>
                                  <asp:ListItem Value="6">6</asp:ListItem>
                                  <asp:ListItem Value="7">7</asp:ListItem>
                                  <asp:ListItem Value="8">8</asp:ListItem>
                                  <asp:ListItem Value="9">9</asp:ListItem>
                                  <asp:ListItem Value="10">10</asp:ListItem>

                          <asp:TemplateField SortExpression="Amount" HeaderText="Amount" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right"  HeaderStyle-Width="60px">
                                  <asp:TextBox ID="TxtRecd"  Text='<%# Bind("Amount") %>' runat="server" Width="100px"   ></asp:TextBox>


it look like after binding:-

ID -- Number -- Amount
101-- 1 -- 500
102-- 1 -- 700

it want that when i change dropdown then dropdown value multiply with amount and now amount are bind with new value. for example in first row i am select 5 in dropdown list then my gridview look like:-

ID -- Number -- Amount
101-- 5 -- 2500
102-- 1 -- 700

What I have tried:

its done fine in but i want to do it with java script.

Protected Sub Multiply(ByVal sender As Object, ByVal e As EventArgs)

Dim row As GridViewRow = TryCast(TryCast(sender, DropDownList).NamingContainer, GridViewRow)
Dim dataKey As String = Me.Gridview1.DataKeys(row.RowIndex).Value.ToString()

Dim ClassesID As String = ViewState("ClassesID")

Dim amount As Integer = ViewState("amount")

Dim n As Integer = CType(GridOtherFee.Rows(row.RowIndex).FindControl("DdlMultiply"), DropDownList).SelectedValue

CType(row.FindControl("TxtRecd"), TextBox).Text = n * amount
End Sub
Peter Leow 11-Jun-16 9:41am
If the user chooses number 2, that amount becomes 1000; what if he changes his mind and select number 1, that amount stays at 1000, is that what you want?
Karthik_Mahalingam 11-Jun-16 9:43am
you can do this in javascript itself
Vincent Maverick Durano 11-Jun-16 12:39pm
Here's an example I wrote many years ago, but it uses a TextBox instead of DropDownList. I'm not on my dev machine now so I cant tweak the code for you. You could take it as a reference and tweak the code so it will work for dropdown.

Here you go:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900