如何在gridview中更改gridview中更改的下拉选择索引中的标签值 [英] how to change a value of label in gridview on dropdown selected index changed in gridview

查看:74
本文介绍了如何在gridview中更改gridview中更改的下拉选择索引中的标签值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的网格视图:

this is my grid view:

<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>





和thi s是代码背后的代码:



and this is my code behind code:

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?


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?

推荐答案

below code will help you getting the current row &控制。 Hope this helps



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

GridViewRow row =(GridViewRow) ddl.NamingContainer;
Control ctrl = row.FindControl("DropDownList1") as DropDownList;


这篇关于如何在gridview中更改gridview中更改的下拉选择索引中的标签值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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