PDA

View Full Version : آموزش: کد نمایش جزییات یک فیلد در Gridview به صورت tooltip



elham1611
دوشنبه 01 آذر 1389, 02:21 صبح
با سلام

اگر فیلدی در گرید ویو داشتیم همانند آدرس (که در ستون اول قرار دارد و میخواهیم فقط 30 حرف اول آن نمایش داده شود ) و بقیه به صورت tooltip باشد .

C#‎‎ code:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ViewState["OrigData"] = e.Row.Cells[0].Text;
if (e.Row.Cells[0].Text.Length >= 30) //Just change the value of 30 based on your requirements
{
e.Row.Cells[0].Text = e.Row.Cells[0].Text.Substring(0, 30) + "...";
e.Row.Cells[0].ToolTip = ViewState["OrigData"].ToString();
}
}
}


VB.Net Code

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
ViewState("OrigData") = e.Row.Cells(0).Text
If e.Row.Cells(0).Text.Length >= 30 Then 'Just change the value of 30 based on your requirements
e.Row.Cells(0).Text = e.Row.Cells(0).Text.Substring(0, 30) + "..."
e.Row.Cells(0).ToolTip = ViewState("OrigData").ToString()
End If
End If
End Sub

L_eskandary
دوشنبه 01 آذر 1389, 12:12 عصر
من با این روش موقعی که می خوام گزارش بگیرم به مشکل بر می خورم :
فرض کنین می خوام اطلاعات گرید رو بفرستم به یه فایل Excel ...
در این صورت آدرس ها تا 30 کاراکتر اول وارد فایل excel می کنه و این میشه یه مشکل اساسی!

elham1611
جمعه 20 اسفند 1389, 15:00 عصر
www.hasheminezhad.com

برو اینجا یه روش خوب واسه گزارش گیری داده تک

elham1611
جمعه 20 اسفند 1389, 15:19 عصر
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ViewState["mahdoodeh"] = e.Row.Cells[7].Text;
if (e.Row.Cells[7].Text.Length >= 10)//Just change the value of 30 based on your requirements</b>
{
e.Row.Cells[7].Text = e.Row.Cells[7].Text.Substring(0,10) + "...";
e.Row.Cells[7].ToolTip = ViewState["mahdoodeh"].ToString();
}
}
}