将值绑定到GridView中的ToolTip Id

时间:2016-06-28 03:47:57

标签: c# asp.net gridview

<div class="panel-body">
    <div class="col-sm-12">
        <div class="panel-body panelscollbar height85">
            <asp:GridView ID="GridView1" CssClass="table table-hover table-striped" runat="server" GridLines="None" ShowHeaderWhenEmpty="True" EmptyDataText="No data found..." AutoGenerateColumns="False">
                <Columns>
                    <asp:TemplateField HeaderText="Company">
                        <ItemTemplate>
                            <asp:Label ID="lbl_Company" runat="server" ToolTip='<%# Bind("companyname") %>' Text='<%# Bind("_mpce_com") %>' Width="100px"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </div>
    </div>
</div>

我想将值绑定到此服务提示ID,该服务提示ID是服务器端的companyname

如何绑定该值,如下面的

protected void lbtnAddPrftCntr_Click(object sender, EventArgs e)
{
    try
    {
      string cmp= ...;

      companyname = cmp;
    }
}

1 个答案:

答案 0 :(得分:0)

在GridView中添加OnRowDataBound="grdAdslCompanyAdvisers_RowDataBound",如

asp:GridView ID="GridView1" OnRowDataBound="GridView1_RowDataBound"

在代码背后

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow) {
            Label lbl = (Label)e.Row.FindControl("lbl_Company");
            lbl.ToolTip = //Your tooltip;
        }
    }