[英]How can I use the GridView datasource in code-behind to not trim text?
嗨,謝謝您的光臨。
我有一個GridView,其數據源設置為一個返回ArrayList的外部類。 現在,在aspx頁面中,我有一個TemplateField,並且Text屬性設置為
Text = '<%#Eval("Name") %>'
除了Name總是被截斷外,即使db中的name值大得多。 我猜由於某種原因,GridView /數據綁定正在截斷名稱? 無論如何,我想在懸停時顯示全名,所以在_RowDataBound事件上,我有e.Row.Cells [2] .ToolTip = something,我不確定該“ something”應該是什么。
在這種情況下,我也可以使用Eval嗎? 如果是這樣,語法將是什么樣的? 如果沒有,我有什么選擇?
很少玩 CSS
和設置tooltip
將解決此問題
背后的代碼:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{ for(int i =0;i <GridView1.Rows.Count;i++)
{
Label lblName = (Label)GridView1.Rows[i].Cells[1].FindControl("lblname");
lblName.ToolTip = "This is my toolTip";// You can set tooltip as Fullname
}
}
Default.aspx:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="gridMyClass"
Width="125px" onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblname" CssClass="myTxtClass" runat="server" Text='<%#Eval("name")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
CSS:
.myTxtClass{
display:inline;
position: relative;
text-decoration:none;
cursor:pointer;
}
.myTxtClass:hover:before{
border: solid;
border-color: red transparent;
border-width: 6px 6px 0 6px;
bottom: 20px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}
.myTxtClass:hover:after{
background-color: red;
opacity:0.7;
border-radius: 5px;
bottom: 26px;
color: #fff;
content: attr(title);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 220px;
}
屏幕截圖:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.