Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Gridview-诸如Eval()、XPath()和Bind()之类的数据绑定方法只能在数据绑定控件的上下文中使用_Asp.net - Fatal编程技术网

Asp.net Gridview-诸如Eval()、XPath()和Bind()之类的数据绑定方法只能在数据绑定控件的上下文中使用

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

问题来自:

double-dItemPremium=(Eval(“Premium”)!=DBNull.Value)?(双倍)(评估(“溢价”):0

我需要帮助改变它

我正在使用Gridview

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>