May i append a text column to a hyperlink column in DataGridView? Thanks!

angel_lee 2006-08-17 01:31:27
May i append a text column to a hyperlink column in DataGridView?

I have two columns, column1 is hyperlink, column2 is text column, may I append column2 to column1, so that they may display as one column which contains hyperlink part and text within one column in GridView?

Thanks a lot!
...全文
494 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
angel_lee 2006-08-22
  • 打赏
  • 举报
回复
Sorry, I typed wrong.

I've solved the string issue by add a server-client method which may process the current string. :)

Thanks a lot!
effun 2006-08-20
  • 打赏
  • 举报
回复
SubString() is a member of String not Eval(). Eval is just a method of DataBinder.
the code you supplied is almost correctly. but i don't know why did you pass the argument 0.200 to SubString() method. i think it should be SubString(0, 200).

in RowDataBound event, you can use FindControl method to get the reference of certain. try the following code. suppose the data source of the GridView is DataTable.

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;

if (row.RowType == DataControlRowType.DataRow)
{
Literal literal = row.FindControl("literal1") as Literal;
DataRowView data = row.DataItem as DataRowView;

if (literal != null && data != null)
{
literal.Text = data["resultDescription"].ToString().SubString(0, 200);
}
}
}
angel_lee 2006-08-19
  • 打赏
  • 举报
回复
Suppose I have a <ItemTemplate> below:

<ItemTemplate>
<asp:Literal ID="literal1" runat="server"></asp:Literal>
<asp:HyperLink ID="hyperLink1" runat="server"></asp:HyperLink>
</ItemTemplate>

For literal1, the text is too long, I want to limited it within 200 chars. But the Eval do not support SubString()?

<asp:Literal ID="literal1" runat="server" Text='<%# (Eval("resultDescription").ToString().SubString(0.200) + "...")%>' />

I could not get the substring in GridView_RowDataBound() either, since literal1 is not a complete cell. What should I do?
amingo 2006-08-19
  • 打赏
  • 举报
回复
UP 2 U
Knight94 2006-08-19
  • 打赏
  • 举报
回复
to <asp:Literal ID="literal1" runat="server" Text='<%# (Eval("resultDescription").ToString().SubString(0.200) + "...")%>' />
I could not get the substring in GridView_RowDataBound() either, since literal1 is not a complete cell. What should I do?

you cannot call server-side methods in client-side.

there are two ways for your problem, details as follows
one is that you add a datacolumn using expressions, such as
yourDataTable.Columns.Add( "BriefDes", typeof(string), "SUBSTRING( resultDescription, 0, 200 )";
and then bind your template column with the field named "BriefDes".
By the way, you can set its column format with "..." at the end.

the other is that you add a server-client method which will process the current string ,
please read the follow article:
http://community.csdn.net/Expert/topicview.asp?id=4213082
angel_lee 2006-08-18
  • 打赏
  • 举报
回复
I was supposed to use ItemTemplate, but vs.net2005 do not support ItemTemplate in GridView. It supports ItemTemplate in FormView. So do i need to change GridView to FormView, or does it have any other object that can be used in GridView ?
Knight94 2006-08-18
  • 打赏
  • 举报
回复
I guess you should choose some way difficult.

for arguments, what you should do is to create one column for them.
Just as follows:

DataColumn dcArguments = yourDataTable.Columns.Add( "Arguments", typeof( string ) );
dcArguments.DafaultValue = "";

//For some detail row
yourDataTable.Rows[yourIndex]["Arguments"] = "COURSEID="+COURSEID.ToSring() + "&CID=" + topicID.ToString();//Compose arguments in one column

//Get navigate url with arguments
strUrl = yourUrl;
if( yourDataTable.Rows[yourIndex]["Arguments"] != "" )
strUrl += "?" + yourDataTable.Rows[yourIndex]["Arguments"].ToString();//Add arguments
jc15271149 2006-08-18
  • 打赏
  • 举报
回复
yes,up
effun 2006-08-18
  • 打赏
  • 举报
回复
you may use a template column instead
foyuan 2006-08-18
  • 打赏
  • 举报
回复
以为走错了 呵呵
effun 2006-08-18
  • 打赏
  • 举报
回复
sample:

<asp:GridView ID="gridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Literal ID="literal1" runat="server"></asp:Literal>
<asp:HyperLink ID="hyperLink1" runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Knight94 2006-08-17
  • 打赏
  • 举报
回复
to is it possible for the GridViewLinkColumn that contains different expressions and arguments to navigate to different pages?

it's possible!

you should save expressions and arguments in some hidden columns.
In the link column's cell click event, you get its expressions and arguments firstly, and compose the navigateiion url with them.
阿牛138588 2006-08-17
  • 打赏
  • 举报
回复
for i =0 to datagridview1.rows.count-1
datagridview1.rows(i).cols(1).value=datagridview1.rows(i).cols(1).tostring +datagridview1.rows(i).cols(2).tostring
next
datagridview1.cols(2).width=0

不知道我有没有理解错你的e文,唉
angel_lee 2006-08-17
  • 打赏
  • 举报
回复
for the arguments, different recorders have different numbers of request arguments to navigate to the new pages. Such as some recorders have 1 request argument, some recorders have 2 request arguments, some have 3 request arguments.

Each request arguments stored in one column. I will add different numbers of columns for different records. So How could I control these request arguments within different columns?

for example:
topic.asp?COURSEID="&COURSEID&"&CID="&topicID&"

(COURSEID and CID means request arguments here.)

angel_lee 2006-08-17
  • 打赏
  • 举报
回复
Thanks Knight94(愚翁) !

is it possible for the GridViewLinkColumn that contains different expressions and arguments to navigate to different pages?

wfhelp 2006-08-17
  • 打赏
  • 举报
回复
为了方便浏览我在这里做个记号收藏
xray2005 2006-08-17
  • 打赏
  • 举报
回复
不懂!
我只会放在一个<td></td>里:
<td><a href='<%#DataBinder.Eval(Container.DataItem,"hyperlink")#%>'><%#DataBinder.Eval(Container.DataItem,"hyperlink")#%></a><%#DataBinder.Eval(Container.DataItem,"text")#%></td>
addwing 2006-08-17
  • 打赏
  • 举报
回复
学习,帮你顶!
weiit 2006-08-17
  • 打赏
  • 举报
回复
up
rola 2006-08-17
  • 打赏
  • 举报
回复
我知道,可惜不知道用英文怎么解释说明做法
加载更多回复(5)

111,132

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧