如何从文本框中获取数据库中的值和+值? [英] How to get value from database and + with value in textbox?

查看:78
本文介绍了如何从文本框中获取数据库中的值和+值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我在带有文本框的数据列表中有som产品。当您在文本框中输入一个数字并单击该按钮时,它可以根据您订购的数量对产品价格进行总结。



我如何获得我的数据库中的值和文本框中的值+它的价值?



我试过这个:



前端



Hi
I have som products in a datalist with a textbox. When you enter a number in the textbox and you click on the button it could make a sum on the products price with how many you orderd.

How does I get the value from my database and + it with the value in the textbox??

I have try this:

Frontend

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [delikatesse]"></asp:SqlDataSource>
            
            
           <div id="ekstra_vare">
                <asp:DataList ID="VisDeli" runat="server" RepeatLayout="Table"
RepeatColumns="4" DataSourceID="SqlDataSource1" OnItemDataBound="VisDeli_ItemDataBound" CellSpacing="5" CssClass="tabel1" >
                    
                    <HeaderTemplate>
                        <p class="overskrift_bestil">Vælg tilbehør</p>
                    </HeaderTemplate>
                    
                    <ItemTemplate>
                 
                          <td><asp:TextBox ID="TextBox_deli" runat="server" Width="15" Height="15"></asp:TextBox></td>
                          <td><p><%#Eval("deli_navn") %></p>
                              <td><p><a class="email" href="#emailpopup?deli_id=">info</a></p></td>

                
                             
            </div>
                               
             

                          </td>
                    
                       
                    </ItemTemplate>
                </asp:DataList>

</div>
            <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [kurve] WHERE kurve_id = 1"></asp:SqlDataSource>
       
            <div id="ekstra_pris">
                <asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSource3">
                    <ItemTemplate>
                        <%#Eval("pris") %> kr.
                    </ItemTemplate>
                </asp:Repeater>
                <asp:Label ID="Label_Vispris" runat="server" Text=""></asp:Label>
                <asp:Button ID="Button1" runat="server" Text="Opdater" OnClick="Button1_Click" />
                 </div>      





后端:





Backend:

protected void Button1_Click(object sender, EventArgs e)
   {
       int totalvaerdi = 0;

       List<ValgtDeli> valgteDeli = new List<ValgtDeli>(); //Her laver jeg en liste over valgte frugter. Det er et nyt objekt, som kan indeholde påde ID, Navn, Antal og Værdi



       foreach (DataListItem item in VisDeli.Items)
       {
           if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
           {
               TextBox Textbox_antal = item.FindControl("TextBox_deli") as TextBox;


               int pris = 149;

               int prisVare = ;

               int enkeltFrugtAntal = int.Parse(Textbox_antal.Text);


               totalvaerdi = pris + enkeltFrugtAntal;


           }

       }
       if (totalvaerdi > 0)
       {

           Label_Vispris.Text = Convert.ToString(totalvaerdi);
       }



   }

推荐答案

ConnectionStrings:ConnectionString%> SelectCommand = SELECT * FROM [delikatesse] < span class =code-keyword>> < / asp:SqlDataSource < span class =code-keyword>>


< div id = ekstra_vare >
< asp:DataList ID = VisDeli runat = server RepeatLayout =
RepeatColumns = 4 DataSour ceID = SqlDataSource1 OnItemDataBound = VisDeli_ItemDataBound CellSpacing = 5 CssClass = tabel1 >

< HeaderTemplate>
< p class = overskrift_bestil >Vælttilbehør< / p >
< / HeaderTemplate >

< ItemTemplate>

< td>< asp:TextBox ID = TextBox_deli runat = server宽度= 15高度= 15 < span class =code-keyword>> < / asp:TextBox < span class =code-keyword>> < / td >
< td>< p><%#Eval( deli_navn%> < / p >
< td>< p>< a class = 电子邮件 href = #emailpopup?deli_id => info < / a > < / p > < / td >



< / div >



< / td <跨度class =code-keyword>>


< / ItemTemplate >
< / asp:DataList >

< / div >
< asp:SqlDataSource ID = SqlDataSource3 runat = server ConnectionString = <%
ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [delikatesse]"></asp:SqlDataSource> <div id="ekstra_vare"> <asp:DataList ID="VisDeli" runat="server" RepeatLayout="Table" RepeatColumns="4" DataSourceID="SqlDataSource1" OnItemDataBound="VisDeli_ItemDataBound" CellSpacing="5" CssClass="tabel1" > <HeaderTemplate> <p class="overskrift_bestil">Vælg tilbehør</p> </HeaderTemplate> <ItemTemplate> <td><asp:TextBox ID="TextBox_deli" runat="server" Width="15" Height="15"></asp:TextBox></td> <td><p><%#Eval("deli_navn") %></p> <td><p><a class="email" href="#emailpopup?deli_id=">info</a></p></td> </div> </td> </ItemTemplate> </asp:DataList> </div> <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%


ConnectionStrings:ConnectionString%> SelectCommand = SELECT * FROM [kurve] WHERE kurv e_id = 1 > < / asp:SqlDataSource >

< div id = ekstra_pris >
< asp:Repeater ID = Repeater2 runat = server DataSourceID = SqlDataSource3 >
< ItemTemplate>
<%#Eval( pris%> kr。
< / ItemTemplate >
< / asp:Repeater >
< asp:标签ID = Label_Vispris runat = server Text = > < / asp:标签 >
< asp:按钮ID = Button1 runat = server Text = Opdater OnClick = Button1_Click />
< / div >
ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [kurve] WHERE kurve_id = 1"></asp:SqlDataSource> <div id="ekstra_pris"> <asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSource3"> <ItemTemplate> <%#Eval("pris") %> kr. </ItemTemplate> </asp:Repeater> <asp:Label ID="Label_Vispris" runat="server" Text=""></asp:Label> <asp:Button ID="Button1" runat="server" Text="Opdater" OnClick="Button1_Click" /> </div>





后端:





Backend:

protected void Button1_Click(object sender, EventArgs e)
   {
       int totalvaerdi = 0;

       List<ValgtDeli> valgteDeli = new List<ValgtDeli>(); //Her laver jeg en liste over valgte frugter. Det er et nyt objekt, som kan indeholde påde ID, Navn, Antal og Værdi



       foreach (DataListItem item in VisDeli.Items)
       {
           if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
           {
               TextBox Textbox_antal = item.FindControl("TextBox_deli") as TextBox;


               int pris = 149;

               int prisVare = ;

               int enkeltFrugtAntal = int.Parse(Textbox_antal.Text);


               totalvaerdi = pris + enkeltFrugtAntal;


           }

       }
       if (totalvaerdi > 0)
       {

           Label_Vispris.Text = Convert.ToString(totalvaerdi);
       }



   }


可能会得到一些帮助从这个...



选择命令 asp:SqlDataSource中的 chang e ..从这个查询中你得到三栏

第一个是' CountOfProduct ',< big> second 是' PriceOfProduct ', third 是' TotalPricce '...



现在该栏目中显示哪些数据

CountOfProduct :显示行数 kurve_id 有关假设你的 kurve_id 3 ,然后在数据库中有五个产品可用于此 kurve_id ,然后 CountOfProduct = 5 ..


$ b $ c> &b中的
; PriceOfProduct
:显示与 kurve_id 相关的产品的价格你输入的所有产品的价格相同,你选择的是 kurve_id ,假设产品 Price = 10 kurve_id = 3 然后 PriceOfProduct = 10



TotalPricce 中:你得到总数您选择的 kurve_id 相关产品的价格



SelectCommand =SELECT COUNT(*)AS CountOfProduct,PriceOfProduct,((COUNT(*))*(PriceOfProduct))AS TotalPricce FROM [kurve] WHERE kurve_id = 1 GROUP BY PriceOfProduct......





现在你可以在你想要的地方使用TotalPricce....



完全希望你能从中得到解决方案...

最好的运气......
may be you get some help from this...

please change in the Select Command of the asp:SqlDataSource ..from this query you get the three column
First is 'CountOfProduct',second is 'PriceOfProduct',third is 'TotalPricce'...

now which data is display in this column
In the CountOfProduct : display count of row which is related to kurve_id in short suppose your kurve_id is 3, then in the database there are five product is available for this kurve_id, then CountOfProduct = 5..

in the >PriceOfProduct : display the Price of Product which is related to kurve_id which you entered and this price is same for the all product and it's kurve_id you select, Suppose for the Product Price =10 of the kurve_id =3 then PriceOfProduct = 10

In the TotalPricce : you get the total price of the Product related to kurve_id which you select.

SelectCommand="SELECT COUNT(*)AS CountOfProduct,PriceOfProduct,((COUNT(*))*(PriceOfProduct))AS TotalPricce FROM [kurve] WHERE kurve_id = 1 GROUP BY PriceOfProduct"...


And Now You Can Use "TotalPricce" Where You Want ....

Hope Fully You got the Solution From this ...
Best Of Luck....


这篇关于如何从文本框中获取数据库中的值和+值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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