如何将DataTable中的数据绑定到Gridview

时间:2014-06-26 17:39:13

标签: c# asp.net gridview

我会详细说明。我正在尝试获取付款失败的说明,并且我想将鼠标悬停在图片或状态上,以查看付款失败的原因说明:

这是用于将数据绑定到Gridview的c#

DataTable BillingDT = new DataTable();

BillingDT = Q.GetBillHistory(SessionVars.Current.varContractID);
BillingDT.Columns.Add("PayNum", System.Type.GetType("System.String"));
BillingDT.Columns.Add("DateStr", System.Type.GetType("System.String"));
BillingDT.Columns.Add("AmountStr", System.Type.GetType("System.String"));
BillingDT.Columns.Add("BalanceStr", System.Type.GetType("System.String"));
BillingDT.Columns.Add("description", System.Type.GetType("System.String"));

string DownPayment = DT.Select("Name = 'DownPayment'")[0][1].ToString();

for (int row = 0; row < BillingDT.Rows.Count; row++)
{
    BillingDT.Rows[row]["PayNum"] = BillingDT.Rows[row]["Payment"].ToString();
    BillingDT.Rows[row]["DateStr"] = Convert.ToDateTime(BillingDT.Rows[row]["paydate"]).ToShortDateString();

    if (BillingDT.Rows[row]["payment"].ToString() == "0") { 
        BillingDT.Rows[row]["PayNum"] = DownPayment; 
    }

    if (BillingDT.Rows[row]["status"].ToString().Length < 1) {
        BillingDT.Rows[row]["status"] = "";
    }

    if (BillingDT.Rows[row]["descript"].ToString().Length < 1) {
        BillingDT.Rows[row]["description"] = "";
    }

    if (BillingDT.Rows[row]["amount"].ToString().Length > 0) { 
        BillingDT.Rows[row]["AmountStr"] = FV.MoneyString(Convert.ToDecimal(BillingDT.Rows[row]["amount"])); 
    }

    BillingDT.Rows[row]["BalanceStr"] = (BillingDT.Rows[row]["balance"].ToString().Length > 0) ? FV.MoneyString(Convert.ToDecimal(BillingDT.Rows[row]["balance"])) : "";
}

BillingHistoryGV.DataSource = BillingDT;
BillingHistoryGV.DataBind();

这是ASP:我想将描述绑定到工具提示的图像:

<asp:TemplateField>
    <ItemTemplate>
        <asp:Image ID="StatusIconImg" runat="server" ImageUrl='<%# GetImage((string)Eval("Status")) %>' />
    </ItemTemplate>
    <ItemStyle HorizontalAlign="Right" Width="20px" />
</asp:TemplateField>

1 个答案:

答案 0 :(得分:0)

如果我正确理解您的问题,您是否只需绑定图像的ToolTip属性? ToolTip='<%# Eval("description") %>'

<asp:Image ID="StatusIconImg" runat="server" ImageUrl='<%# GetImage((string)Eval("Status")) %>' ToolTip='<%# Eval("description") %>' />