如何在asp.net中添加工具提示
问题描述:
如何为gridview单元格添加工具提示以及如何为该工具提示添加样式....
How to add tool tip for gridview cells and how to add styles for that tool tip....
答
试试这个:
Try This :
<asp:gridview id="GridView1" runat="server">
<columns>
<asp:templatefield headertext="Title">
<itemtemplate>
<asp:linkbutton id="link1" runat="server" commandname="link" forecolor="Blue" tooltip="<%# String.Format("your String :{0}", Eval("field_name from db for tooltip"))%>"> <%#Eval("filed")%></asp:linkbutton>
</itemtemplate>
<itemstyle forecolor="Blue" font-size="Medium" />
</asp:templatefield>
</columns>
</asp:gridview>
this will help you for your problem. you must bind the grid first.
If not, please post it.
Mitesh
Mitesh
>
非常简单。在行数据事件上您可以向单元格添加工具提示。
步骤1:创建新应用程序:
添加页面名称:gridTooltip
步骤2:在gridTooltip.aspx页面中添加以下代码:
Its very simple. On row data event You can add tooltip to a Cell.
Step1: Create a new Application:
Add a page name: gridTooltip
Step2: Add the following code inside the gridTooltip.aspx page:
<asp:gridview id="GridView1" runat="server" onrowdatabound="GridView1_RowDataBound" xmlns:asp="#unknown">
</asp:gridview>
步骤3:在gridTooltip.aspx.cs页面中添加以下代码:
Step3: Inside gridTooltip.aspx.cs page add the following code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
public class Data
{
public string Name
{
get;
set;
}
public int Age
{
get;
set;
}
}
public void BindGrid()
{
Data obj = new Data();
obj.Name = "Kabir";
obj.Age = 28;
Data obj1 = new Data();
obj1.Name = "Safiul";
obj1.Age = 28;
List<Data> olist = new List<Data>();
olist.Add(obj);
olist.Add(obj1);
GridView1.DataSource = olist;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].ToolTip = "My Name is: " + e.Row.Cells[0].Text;
e.Row.Cells[1].ToolTip = "My age is: " + e.Row.Cells[1].Text;
}
}
----现在运行应用程序。
---希望它能帮到你
添加的代码块[/ Edit]
---- Now run the application.
--- Hope it will help you
Code blocks added[/Edit]