Javascript 如何将对象绑定到按钮-ASP.NET(与C标记属性等效)
我正在创建一个asp.net销售点系统。在我的表单上,我使用AJAX选项卡容器从数据库中动态填充所有产品作为按钮Javascript 如何将对象绑定到按钮-ASP.NET(与C标记属性等效),javascript,c#,jquery,asp.net,Javascript,C#,Jquery,Asp.net,我正在创建一个asp.net销售点系统。在我的表单上,我使用AJAX选项卡容器从数据库中动态填充所有产品作为按钮 private void AddProductsToTab() { int i = 1; foreach (AjaxControlToolkit.TabPanel tp in TabContainer1.Tabs) { ObjectContext objectContext = ((IObjectContextAdapter)rdb).Obje
private void AddProductsToTab()
{
int i = 1;
foreach (AjaxControlToolkit.TabPanel tp in TabContainer1.Tabs)
{
ObjectContext objectContext = ((IObjectContextAdapter)rdb).ObjectContext; //we cast our database to an object context, so we can use it in the ObjectQuery.
ObjectQuery<tblProduct> filteredProduct = new ObjectQuery<tblProduct>("SELECT VALUE P FROM tblProducts AS P WHERE P.ProductType = " + i.ToString(),objectContext);
foreach (tblProduct tprod in filteredProduct)
{
Button b = new Button();
b.Height = 100;
b.Width=100;
b.Text = tprod.Description;
tp.Controls.Add(b);
}
i++;
}
}
对于我的数据库,我使用代码优先实体框架,因此我将DB实体作为类tblProduct。我有一个列表框,希望在单击选项卡容器中的产品按钮时,列表框上显示该产品的名称和价格
private void AddProductsToTab()
{
int i = 1;
foreach (AjaxControlToolkit.TabPanel tp in TabContainer1.Tabs)
{
ObjectContext objectContext = ((IObjectContextAdapter)rdb).ObjectContext; //we cast our database to an object context, so we can use it in the ObjectQuery.
ObjectQuery<tblProduct> filteredProduct = new ObjectQuery<tblProduct>("SELECT VALUE P FROM tblProducts AS P WHERE P.ProductType = " + i.ToString(),objectContext);
foreach (tblProduct tprod in filteredProduct)
{
Button b = new Button();
b.Height = 100;
b.Width=100;
b.Text = tprod.Description;
b.CssClass = "product-button";
b.Attributes["data-name"] = tprod.Name;
b.Attributes["data-price"] = tprod.Price;
tp.Controls.Add(b);
}
i++;
}
}
在C语言中,当我创建按钮时,我可以使用我的caseB.Tag属性将我的对象产品放入按钮中,然后对其使用click事件。但在asp.net中,按钮上不存在标记属性。我怎样才能克服这个问题?我可以使用数据绑定吗?您可以将产品名称和价格设置为按钮的数据属性。单击产品按钮时,可以使用jQuery从该按钮的数据属性中获取产品名称和价格,并将其显示在列表框中
private void AddProductsToTab()
{
int i = 1;
foreach (AjaxControlToolkit.TabPanel tp in TabContainer1.Tabs)
{
ObjectContext objectContext = ((IObjectContextAdapter)rdb).ObjectContext; //we cast our database to an object context, so we can use it in the ObjectQuery.
ObjectQuery<tblProduct> filteredProduct = new ObjectQuery<tblProduct>("SELECT VALUE P FROM tblProducts AS P WHERE P.ProductType = " + i.ToString(),objectContext);
foreach (tblProduct tprod in filteredProduct)
{
Button b = new Button();
b.Height = 100;
b.Width=100;
b.Text = tprod.Description;
b.CssClass = "product-button";
b.Attributes["data-name"] = tprod.Name;
b.Attributes["data-price"] = tprod.Price;
tp.Controls.Add(b);
}
i++;
}
}
非常感谢。我会在吸收并尝试这一点后尽快给您反馈,因为我对jQuery比较陌生。