안녕하세요 제 문제는 필자가 항상 URL이있는 TweetText라는 그리드보기의 열이 있다는 것입니다. 그 URl을 클릭 할 수있는 링크로 만들고 싶습니다. 페이지로드시이 작업을 수행했습니다. 그러나 그리드의 페이지 번호를 변경하면 TweetText의 텍스트는 동일하게 유지됩니다. 여기에 내 코드를 작성하십시오. 나는 GridView1_PageIndexChanged에서이 코드를 수행하고있다. 그러나 아무것도 도움이되지 않습니다. 한 가지 더 중요한 것은 전체 열에 링크가 있기를 원하지 않는다는 것입니다. 난 그냥 DataNavigateUrlFormatString
동적텍스트를 gridview asp.net의 링크로 변환
if (!Page.IsPostBack)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
String Url = SmartyPlants.Classes.TwitterData.GetUrlStrings(row.Cells[5].Text);
bool Check = SmartyPlants.Classes.TwitterData.IsUrlValid(Url);
int Index = Url.IndexOf(" ");
if (Url.Contains(" "))
{
Url = Url.Remove(Index);
}
String link = MakeLink(Url);
row.Cells[5].Text = row.Cells[5].Text.Replace(Url, link);
}
}
public static string MakeLink(string txt)
{
Regex regx = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase);
MatchCollection mactches = regx.Matches(txt);
foreach (Match match in mactches)
{
txt = txt.Replace(match.Value, "<a href='" + match.Value + "'>" + match.Value + "</a>");
}
public static bool IsUrlValid(string url)
{
return Regex.IsMatch(url, @"(http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
}
public static string GetUrlStrings(string text)
{
MatchCollection ms = Regex.Matches(text, @"(www.+|http.+)([\s]|$)");
string testMatch = ms[0].Value.ToString();
return testMatch;
}
return txt;
}
는 그리드 마크 업을 제공하는 방법이 URL을 얻고있다 ??? 일부 데이터 원본 열 항목이 있습니까 ?? –
coloumn을 Template col로 만들고 를 추가하십시오. RowDataBound에서 그냥 태그를 찾아서 src를 설정합니다. (src는 리다이렉션해야 할 곳을 의미합니다.) – kbvishnu
한 가지 더 해보면 전체 열에 링크가 있어야합니다. 난 그냥 칼럼에있는 URL을 링크로 만들고 싶다. –