Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
this is my grid view:
XML
<asp:GridView ID="GridView1" runat="server" BackColor="White" AutoGenerateColumns="false"
        BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" Width="1000px"
        EnableModelValidation="True" GridLines="Vertical"   DataKeyNames="movie_id"
        onrowdatabound="GridView1_RowDataBound" onrowdeleted="GridView1_RowDeleted"
            onrowdeleting="GridView1_RowDeleting"  onrowcommand="GridView1_RowCommand">
        <AlternatingRowStyle BackColor="#DCDCDC" />
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <Columns>
        <asp:TemplateField Visible="false" >
                    <ItemTemplate>
                    <asp:Label ID="EmpIDLabel" runat="server" Text='<%# Eval("movie_id") %>' ></asp:Label>
                    </ItemTemplate>
                    </asp:TemplateField>
        <asp:TemplateField HeaderText="Item Description">
        <ItemTemplate>
        <table  cellspacing="5" width="200px" >
    <tr>
    <td style="width:40%" >
    <div class="imgautoformat" style="height:110px;width:81px" >
    <img class="ader1" src='<%#"uploaded/"+ Eval("Movie_Name") %>' alt='<%# Eval("Movie_Name") %>' width="70px"
      height="100" />
      </div>
        </td>
        <td class="lbltxt" style="width:40%" >
        <asp:Label ID="labelLabel" runat="server" Text='<%# Eval("label") %>' />
        <br />
      <b style="color:Red" >  &#36
        <asp:Label ID="priceLabel" runat="server" Text='<%# Eval("price") %>'/></b>
        <br />

        </td>

</tr>
</table>
        </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Delete from cart">
        <ItemTemplate>
         <asp:Button runat="server" ID="btn2del" Text="Remove" CommandArgument='<%# Eval("movie_id") %>' CommandName="Delete" />
        </ItemTemplate>
        </asp:TemplateField>
         <asp:TemplateField HeaderText="Quantity">
        <ItemTemplate>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dd1_selectedindexchanged" >
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>2</asp:ListItem>
                <asp:ListItem>3</asp:ListItem>
                <asp:ListItem>4</asp:ListItem>
                <asp:ListItem>5</asp:ListItem>
                <asp:ListItem>6</asp:ListItem>
            </asp:DropDownList>
        </ItemTemplate>
        </asp:TemplateField>
         <asp:TemplateField HeaderText="Estimated delivery">
        <ItemTemplate>
          <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>

        </ItemTemplate>
        </asp:TemplateField>
         <asp:TemplateField HeaderText="Price">
        <ItemTemplate>
          <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

        </ItemTemplate>
        </asp:TemplateField>

        </Columns>
    </asp:GridView>


and this is my code behind code:
C#
protected void Page_Load(object sender, EventArgs e)
       {
   GridView1.DataSource = from st in obj.Cart_tables
                                       join x in obj.movie_details on st.movie_id equals x.Id
                                       where st.username == (Session["user"]).ToString()
                                       select new { x.Image_path, st.movie_id, x.label, x.price, x.Movie_Name };
                GridView1.DataBind();

}
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {


            if (e.CommandName == "Delete")
            {
                Int32 id = Convert.ToInt32(e.CommandArgument.ToString());
                Cart_table objadsmtp = obj.Cart_tables.Where(a => a.movie_id.Equals(id) && a.username == Session["user"]).SingleOrDefault();

                obj.Cart_tables.DeleteOnSubmit(objadsmtp);
                obj.SubmitChanges();


            }
        }

        protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
            GridView1.DataSource = from st in obj.Cart_tables
                                   join x in obj.movie_details on st.movie_id equals x.Id
                                   where st.username == (Session["user"]).ToString()
                                   select new { x.Image_path, x.label, x.price, x.Movie_Name };
            GridView1.DataBind();
        }
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridView1.DataSource = from st in obj.Cart_tables
                                   join x in obj.movie_details on st.movie_id equals x.Id
                                   where st.username == (Session["user"]).ToString()
                                   select new { x.Image_path, st.movie_id, x.label, x.price, x.Movie_Name };
            GridView1.DataBind();
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            
        }
        protected void dd1_selectedindexchanged(object sender, EventArgs e)
        {
            DropDownList DropDownList1 = sender as DropDownList;
            foreach (GridViewRow row in GridView1.Rows)
            {
                Control ctrl = row.FindControl("DropDownList1") as DropDownList;
                Control ctr = row.FindControl("Label2") as Label;
                    Label Label2 = row.FindControl("Label2") as Label;
                        Label2.Text = DropDownList1.SelectedValue;
                     
               
                
            }
        }

now i want that for all the movies price is coming from database
and when i select quantity from dropdown then the price should be multiply be selected quantity and then show it in label 2 for each row and then add total price and store this value in to a variable?
Posted
Updated 23-Sep-13 21:24pm
v5

1 solution

below code will help you getting the current row & control. Hope this helps

C#
GridViewRow row =(GridViewRow) ddl.NamingContainer;
Control ctrl = row.FindControl("DropDownList1") as DropDownList;
 
Share this answer
 
v2

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