Asp.net Gridview-诸如Eval()、XPath()和Bind()之类的数据绑定方法只能在数据绑定控件的上下文中使用
问题来自: double-dItemPremium=(Eval(“Premium”)!=DBNull.Value)?(双倍)(评估(“溢价”):0 我需要帮助改变它 我正在使用GridviewAsp.net Gridview-诸如Eval()、XPath()和Bind()之类的数据绑定方法只能在数据绑定控件的上下文中使用,asp.net,Asp.net,问题来自: double-dItemPremium=(Eval(“Premium”)!=DBNull.Value)?(双倍)(评估(“溢价”):0 我需要帮助改变它 我正在使用Gridview protected void dgCustomer_DataBound(object sender, System.EventArgs e) { Label pLabel = new Label(); double dItemPremium = (E
protected void dgCustomer_DataBound(object sender, System.EventArgs e)
{
Label pLabel = new Label();
double dItemPremium = (Eval("Premium")!= DBNull.Value) ? (double)(Eval("Premium")) : 0;
pLabel.Text = dItemPremium.ToString("0.00");
dTotal_m += dItemPremium;
dgCustomer.HeaderRow.TableSection = TableRowSection.TableHeader;
dgCustomer.FooterRow.TableSection = TableRowSection.TableFooter;
dgCustomer.FooterRow.Controls.Add(pLabel);
}
protected void dgCustomer_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
dTotal_m += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem,"Premium"));
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = "Totals:";
e.Row.Cells[1].Text = dTotal_m.ToString("0.00");
e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right;
e.Row.Font.Bold = true;
}
}
我用的是HTML
<asp:TemplateField>
<ItemTemplate>
<%#DataBinder.Eval(DataItem,"Premium")%></ItemTemplate>
<HeaderTemplate>
Premium Amount Paid</HeaderTemplate>
</asp:TemplateField>
已付保费
我添加了DataBinder和DataItem,但仍然没有添加任何内容
谢谢大家! 您可以使用控件访问代码隐藏中的绑定值。Eval、Bind等方法用于将值绑定到控件。在代码bebind中,有许多方法可以访问绑定值,其中之一是
e.Row.Cells[0].Text
另一种方法是将绑定值放入标签中并像
string tempstr=((Label)dgCustomer.Rows[e.RowIndex].Cells[<cell_number>].FindControl("Label_ID")).Text;
string tempstr=((Label)dgCustomer.Rows[e.RowIndex].Cells[].FindControl(“Label_ID”)).Text;
如果有人遇到这个问题,这里有另一个解决方案:在aspx文件中,从@user3508633更改为@user3508633,我为您感到高兴。
<ItemTemplate>
<%= DataBinder.Eval(DataItem,"Premium")%></ItemTemplate>
<HeaderTemplate>