【问题标题】:How do I bind Data from my DataTable to Gridview如何将 DataTable 中的数据绑定到 Gridview
【发布时间】:2014-06-26 17:39:13
【问题描述】:

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

这是获取绑定到 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:Image:

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

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

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

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

    【讨论】:

    • 我的问题是使用“描述”而不是仅使用来自 SQL 表的字段“描述”。它现在正在工作!谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 2014-12-22
    • 1970-01-01
    • 2019-01-28
    相关资源
    最近更新 更多