用jquery面对datalist中的问题 [英] facing problem in datalist with jquery

查看:75
本文介绍了用jquery面对datalist中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datalist,它包含一个按钮。在按钮上单击我调用jquery使图像飞行图像动画像添加到购物车和我调用itemcommand函数添加datalist值到gridview但是在调用jquery后我无法调用datalist itemcommand函数所以我创建了静态方法的wb服务来调用后面的代码但我无法获得datalist项目字段值

我的数据主义者喜欢

I am having a datalist and it contains a button. On button click i am calling jquery to make image fly images animation like add to cart and i called itemcommand function for adding datalist value to gridview but after calling jquery i cant call datalist itemcommand function so i created static method of wb service to call code behind but i cant get the datalist item field value
my datalist lok like

<asp:DataList ID="DataList2" runat="server" Width="100%" CssClass="datalisttop" BackColor="White" Height="200px" OnItemCommand="DataList2_ItemCommand">
<ItemTemplate>
<ul>
 <li class="cart_items">
 <div class="content">

 <table cellspacing="0" cellpadding="0" width="100%" style="border-bottom-style: dotted; border-bottom-width: thin; border-color: #9E9E9E;">
 <tr>
<td align="left">

<a href="#" class="product-image">
 <img  src='<%# DataBinder.Eval(Container.DataItem, "ShopCoverPic") %>' width="50" height="50" alt='<%# DataBinder.Eval(Container.DataItem, "ShopID") %>' />
 </a>

 </td>
      <td width="200px">
  <table width="250px" cellspacing="0" cellpadding="0" style="padding-left: 25px">
  <tr>
 <td align="left">
   <asp:HyperLink ID="hlView" runat="server" CssClass="hyperlnk" NavigateUrl='<%# Eval("ShopID", "~/Shop/ShopPage.aspx?ShopID={0}&pageid=1") %>'>
   <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ShopName") %>' CssClass="datalisttop"></asp:Label>
     </asp:HyperLink>
 </td>
</tr>
 <tr>
 <td align="left">
 <asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ShopArea") %>' CssClass="datalisttop"></asp:Label>
</td>
</tr>
 <tr>
 <td align="left">
 <asp:Label ID="Label5" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Productname") %>' CssClass="datalistlbl"></asp:Label>
</td>
 </tr>
 </table>
 </td>
<td align="center" style="padding-left: 15px; padding-right: 15px">
<asp:CheckBox ID="CheckBox1" runat="server" CssClass="mycheck" OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="true" />
 </td>
<td>
<table cellspacing="0" cellpadding="0" width="200px">
<tr>
 <td align="center">
 <asp:Label ID="Label6" runat="server" Text="Actual Price:" CssClass="datalisttoplbl"></asp:Label><asp:Label ID="Label7" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "BMRP") %>' CssClass="datalisttoplbl"></asp:Label>
 </td>
 </tr>
 <tr>
 <td align="center">
   <asp:Label ID="Label8" runat="server" Text="Offer Price:" CssClass="datalistbotlbl"></asp:Label><asp:Label ID="Label9" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "AMRP") %>' CssClass="datalistbotlbl"></asp:Label>
 </td>
</tr>
</table>
 </td>
<td align="center">

 </td>
  <td></td>
 </tr>

</table>
 <br />
</div>
 </li>

</ul>
</ItemTemplate>

 </asp:DataList>

&&&







jquery






jquery

<script type='text/javascript'> jQuery(function ($) {

     $('.add-to-cart').click(function () {
         var arr = [];
         var foo = document.getElementById("<%= DataList2.ClientID %>");
         var inps = foo.getElementsByTagName("input");

         for (var i = 0; i < inps.length; i++) {
             arr.push(inps[i].te)
             alert(arr.pop());


         }
         $.ajax({
             type: "POST",
             url: "Shopinnerpage.aspx/cartFunction",
             data: '{itemCount: arr}',
             contentType: "application/json; charset=utf-8",
             dataType: "json",
             success: OnSuccess,
             failure: function (response) {
                 alert(response.d);
             }
         });

         function OnSuccess(response) {
             alert(response.d);
         }
         var cart = $('.shopping_bg');

         var imgtofly = $(this).parents('li.cart_items').find('a.product-image img').eq(0);
         if (imgtofly) {
             var imgclone = imgtofly.clone()
                 .offset({ top: imgtofly.offset().top, left: imgtofly.offset().left })
                 .css({ 'opacity': '0.7', 'position': 'absolute', 'height': '150px', 'width': '150px', 'z-index': '1000' })
                 .appendTo($('body'))
                 .animate({
                     'top': cart.offset().top + 10,
                     'left': cart.offset().left + 30,
                     'width': 55,
                     'height': 55
                 }, 1000, 'easeInElastic');
             imgclone.animate({ 'width': 0, 'height': 0 },  function () {
                 $(this).detach()


             });
         }
         return false;
     });
 });


</script>







代码落后

[WebMethod]

public static string cartFunction(string [] itemCount)

{



return ;



}



[WebMethod]

protected void DataList2_ItemCommand(object source,DataListCommandEventArgs e)

{

int index = e.Item.ItemIndex;

int cnt = Convert.ToInt32(Label10.Text) ;

if(cnt< 3)

{

cnt = cnt + 1;



Label10.Text = cnt.ToString();

DataTable dt1 = new DataTable();

DataColumn ShopName = ne w DataColumn(ShopName);

DataColumn ShopArea = new DataColumn(ShopArea);

DataColumn Actual_Price = new DataColumn(Actual_Price);

DataColumn Offer_Price = new DataColumn(Offer_Price);

dt1.Columns.Add(ShopName);

dt1.Columns.Add(ShopArea);

dt1.Columns.Add(Actual_Price);

dt1.Columns.Add(Offer_Price);

for(int j = 0; j< gvsms.Rows.Count; j ++)

{

//将文本框值放入gridview coloumn和行

DataRow博士;

GridViewRow行= gvsms.Rows [j];

dr = dt1.NewRow();

for(int i = 0; i< 4; i ++)

{

dr [i] = row.Cells [i] .Text;

}



dt1.Rows.Add(dr);

}

DataRow dr1 = dt1.NewRow();



BoundField bfield = new BoundField();

//将文本框值放入gridview中的特定行

string shpname = Convert.ToString(((Label)DataList2.Items [index] .FindControl(Label1))。文本);

string shparea = Conve rt.ToString(((Label)DataList2.Items [index] .FindControl(Label3))。Text);

string actualprice = Convert.ToString(((Label)DataList2.Items [index ].FindControl(\"Label6\")).Text);

string offerprice = Convert.ToString(((Label)DataList2.Items[index].FindControl(\"Label8\")).Text);

dr1[\"ShopName\"] = shpname;

dr1[\"ShopArea\"] = shparea;

dr1[\"Actual_Price\"] = actualprice ;

dr1[\"Offer_Price\"] = offerprice;

dt1.Rows.Add(dr1);

gvsms.DataSource = dt1;

gvsms.DataBind();



}



else

{

// ScriptManager.RegisterStartupScript(this, GetType(), \"showalert\", \"alert('Maximum 3 product can be sent’);\", true);

}



}




code behind
[WebMethod]
public static string cartFunction(string[] itemCount)
{

return "";

}

[WebMethod]
protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
{
int index = e.Item.ItemIndex;
int cnt = Convert.ToInt32(Label10.Text);
if (cnt < 3)
{
cnt = cnt + 1;

Label10.Text = cnt.ToString();
DataTable dt1 = new DataTable();
DataColumn ShopName = new DataColumn("ShopName");
DataColumn ShopArea = new DataColumn("ShopArea");
DataColumn Actual_Price = new DataColumn("Actual_Price");
DataColumn Offer_Price = new DataColumn("Offer_Price");
dt1.Columns.Add(ShopName);
dt1.Columns.Add(ShopArea);
dt1.Columns.Add(Actual_Price);
dt1.Columns.Add(Offer_Price);
for (int j = 0; j < gvsms.Rows.Count; j++)
{
//Putting textbox values into gridview coloumn and row
DataRow dr;
GridViewRow row = gvsms.Rows[j];
dr = dt1.NewRow();
for (int i = 0; i < 4; i++)
{
dr[i] = row.Cells[i].Text;
}

dt1.Rows.Add(dr);
}
DataRow dr1 = dt1.NewRow();

BoundField bfield = new BoundField();
//Textbox values into particular row in gridview
string shpname = Convert.ToString(((Label)DataList2.Items[index].FindControl("Label1")).Text);
string shparea = Convert.ToString(((Label)DataList2.Items[index].FindControl("Label3")).Text);
string actualprice = Convert.ToString(((Label)DataList2.Items[index].FindControl("Label6")).Text);
string offerprice = Convert.ToString(((Label)DataList2.Items[index].FindControl("Label8")).Text);
dr1["ShopName"] = shpname;
dr1["ShopArea"] = shparea;
dr1["Actual_Price"] = actualprice;
dr1["Offer_Price"] = offerprice;
dt1.Rows.Add(dr1);
gvsms.DataSource = dt1;
gvsms.DataBind();

}

else
{
// ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Maximum 3 product can be sent');", true);
}

}

推荐答案

) {


('.add-to-cart').click(function () {
var arr = [];
var foo = document.getElementById(\"<%= DataList2.ClientID %>\");
var inps = foo.getElementsByTagName(\"input\");

for (var i = 0; i < inps.length; i++) {
arr.push(inps[i].te)
alert(arr.pop());


}
('.add-to-cart').click(function () { var arr = []; var foo = document.getElementById("<%= DataList2.ClientID %>"); var inps = foo.getElementsByTagName("input"); for (var i = 0; i < inps.length; i++) { arr.push(inps[i].te) alert(arr.pop()); }


.ajax({
type: \"POST\",
url: \"Shopinnerpage.aspx/cartFunction\",
data: '{itemCount: arr}',
contentType: \"application/json; charset=utf-8\",
dataType: \"json\",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});

function OnSuccess(response) {
alert(response.d);
}
var cart =
.ajax({ type: "POST", url: "Shopinnerpage.aspx/cartFunction", data: '{itemCount: arr}', contentType: "application/json; charset=utf-8", dataType: "json", success: OnSuccess, failure: function (response) { alert(response.d); } }); function OnSuccess(response) { alert(response.d); } var cart =


这篇关于用jquery面对datalist中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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