Hi All,
at my "Tag.ascx.cs" file
string myTag = String.Format(CultureInfo.InvariantCulture, "http://ec2-67-202-62-133.compute-1.amazonaws.com/index.php?key=8f6dd47c952c8c6b4937e345294cbc96&keyword={0}", tag.Name);
tag.Name will be gaven based on user's selection. Say we have tag.Name = "art" , then will have following URL:
http://ec2-67-202-62-133.compute-1.amazonaws.com/index.php?key=8f6dd47c952c8c6b4937e345294cbc96&keyword=art (if you paste this URL on your browser, you will see:
[{"name": "Culture", "rank": 0.71720810000000002, "coef":
0.13953489999999999}, {"name": "Artist", "rank": 0.65750759999999997,
"coef": 0.10000000000000001}, {"name": "Theater", "rank":
0.55500649999999996, "coef": 0.090909100000000007}, {"name":
"Festival", "rank": 0.53509759999999995, "coef": 0.071428599999999995},
{"name": "Asian American", "rank": 0.53509759999999995, "coef":
0.071428599999999995}, {"name": "Diversity", "rank":
0.52829020000000004, "coef": 0.088235300000000003}, {"name":
"PHOTOGRAPHY", "rank": 0.48868289999999998, "coef":
0.068965499999999999}, {"name": "HIP HOP", "rank": 0.42419839999999998,
"coef": 0.064516100000000007}, {"name": "Theatre", "rank":
0.42419839999999998, "coef": 0.064516100000000007}, {"name": "Film",
"rank": 0.39954709999999999, "coef": 0.0625}]
what I want to show on my "Tag.ascx" file is Culture, Artist, Theater, Festival, Asian American, Diversity, PHOTOGRAPHY, HIP HOP, Theatre, Film
How can I get this task done?
Thank you in advance for your time.
ellen
Loading
Kirtan PatelPosted Dec 14, 2009, 11:01 PM
using System.Net;
using System.Threading;
using System.IO;
using System.Text.RegularExpressions;
protected void Page_Load(object sender, EventArgs e)
{
WebClient wc = new WebClient();
wc.DownloadFile("http://ec2-67-202-62-133.compute-1.amazonaws.com/index.php?key=8f6dd47c952c8c6b4937e345294cbc96&keyword=art", "data.txt");
//Process Data
string TextData = File.ReadAllText("data.txt");
//Removeing [ ]
TextData = TextData.Replace("[", String.Empty);
TextData = TextData.Replace("]", String.Empty);
String NewData = "";
// FreeUp Spaces
foreach (char c in TextData.ToCharArray())
{
if (c != ' ')
{
NewData += c.ToString();
}
}
string data = Regex.Replace(NewData, "[\"]*", String.Empty);
Regex DataDelim = new Regex("{name:[a-zA-Z]*,rank:[0-9.]*,coef:[0-9.]*}");
MatchCollection mc = DataDelim.Matches(data);
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Rank");
dt.Columns.Add("Coef");
foreach (Match m in mc)
{
string matchdata = m.Value.ToString();
//remove {} from match
matchdata = Regex.Replace(matchdata, "[{]*[}]*", string.Empty);
string[] dataparts = matchdata.Split(',');
List<string> drlist = new List<string>();
drlist.Clear();
foreach(string s in dataparts)
{
string[] rowpart = s.Split(':');
drlist.Add(rowpart[1]);
}
DataRow dr = dt.NewRow();
dr[0] = drlist[0];
dr[1] = drlist[1];
dr[2] = drlist[2];
dt.Rows.Add(dr);
}
GridView1.DataSource = dt;
DataBind();
}
Ellen HuPosted Dec 17, 2009, 3:30 PM
here is the code, in case could help somebody.
on my Tag.ascx
style="padding-left:2px;padding-right:2px;padding-top:1px;padding-bottom:1px;" OnCommand="hlTag_Command" >
on Tag.ascx.cs file
public byte[] originalData;
protected void Page_Load( object sender, EventArgs e )
{
ITag tag = null;
if (!String.IsNullOrEmpty(Request["Tag"]))
{
try
{
int tagID = Int32.Parse(Request["Tag"], CultureInfo.InvariantCulture);
tag = TagFactory.GetITag(tagID);
}
catch (FormatException) { }
}
if (!IsPostBack)
{
if (tag != null)
{
string TextData = "";
WebClient wc = new WebClient();
string myTagUrl = String.Format(CultureInfo.InvariantCulture, "http://ec2-67-202-62-133.compute-1.amazonaws.com/index.php?key=8f6dd47c952c8c6b4937e345294cbc96&keyword={0}", tag.Name);
try
{
originalData = wc.DownloadData(myTagUrl);
}
catch (WebException)
{
// do nothing
}
if (originalData != null)
{
MemoryStream stream = new MemoryStream(originalData);
TextData = new StreamReader(stream).ReadToEnd();
//Removeing [ ]
TextData = TextData.Replace("[", String.Empty);
TextData = TextData.Replace("]", String.Empty);
String NewData = "";
int ii = 0;
// FreeUp Spaces
bool addSpace = false;
foreach (char c in TextData.ToCharArray())
{
//don't remove the spaces within Name
if (c == '"')
{
ii++;
NewData += c.ToString();
if (ii % 2 == 1)
{
addSpace = true;
}
else
{
addSpace = false;
}
}
if (addSpace && c != ' ')
{
NewData += c.ToString();
}
else if (addSpace && c == ' ')
{
NewData += '-';
}
if (c != ' ' && !addSpace)
{
NewData += c.ToString();
}
}
string data = Regex.Replace(NewData, "[\"]*", String.Empty);
Regex DataDelim = new Regex("{name:[a-zA-Z-]*,rank:[0-9.]*,coef:[0-9.]*}");
MatchCollection mc = DataDelim.Matches(data);
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Rank");
dt.Columns.Add("Coef");
foreach (Match m in mc)
{
string matchdata = m.Value.ToString();
//remove {} from match
matchdata = Regex.Replace(matchdata, "[{]*[}]*", string.Empty);
string[] dataparts = matchdata.Split(',');
List
drlist.Clear();
foreach (string s in dataparts)
{
string[] rowpart = s.Split(':');
drlist.Add(rowpart[1]);
}
DataRow dr = dt.NewRow();
dr[0] = drlist[0];
dr[1] = drlist[1];
dr[2] = drlist[2];
dt.Rows.Add(dr);
}
rptTags.DataSource = dt;
rptTags.DataBind();
}
}
}
}
Thank you again for always help from this site.
ellen
Ellen HuPosted Dec 16, 2009, 12:48 AM
But I have more question need to ask.
what I want to show on my "Tag.ascx" file is Culture, Artist, Theater, Festival, Asian American, Diversity, PHOTOGRAPHY, HIP HOP, Theater, Film
those names are buttons, if the button is clicked, then gridview needs to be reloaded. Say "Culture" is clicked, it should go "http://ec2-67-202-62-133.compute-1.amazonaws.com/index.php?key=8f6dd47c952c8c6b4937e345294cbc96&keyword=culture" to get the file, reload gridview again.
I have to use linkbutton, but what is "ItemDataBound" at .cs file, I don't want to use bondfield at ascx file
Thank you,
ellen