| using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender,EventArgs e) { GridView1.DataSource = GetData(); GridView1.DataBind(); } public static string GenerateURL(object Title, object strId) { string strTitle = Title.ToString(); //#region Generate SEO Friendly URL based on Title strTitle = strTitle.Trim(); strTitle = strTitle.Trim('-'); strTitle = strTitle.ToLower(); char[] chars =@"$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray(); strTitle = strTitle.Replace("c#","C-Sharp"); strTitle = strTitle.Replace("vb.net","VB-Net"); strTitle = strTitle.Replace("asp.net","Asp-Net"); strTitle = strTitle.Replace(".","-"); for (int i = 0; i < chars.Length; i++) { string strChar = chars.GetValue(i).ToString(); if (strTitle.Contains(strChar)) { strTitle = strTitle.Replace(strChar, string.Empty); } } strTitle = strTitle.Replace(" ","-"); strTitle = strTitle.Replace("--","-"); strTitle = strTitle.Replace("---","-"); strTitle = strTitle.Replace("----","-"); strTitle = strTitle.Replace("-----","-"); strTitle = strTitle.Replace("----","-"); strTitle = strTitle.Replace("---","-"); strTitle = strTitle.Replace("--","-"); strTitle = strTitle.Trim(); strTitle = strTitle.Trim('-'); strTitle ="~/Article/" + strTitle +"-" + strId +".aspx"; return strTitle; } private DataTable GetData() { string strConn = ("Data Source=.; uid=sa; pwd=Password$2; database=userinfo"); SqlConnection conn =new SqlConnection(strConn); SqlDataAdapter da =new SqlDataAdapter("select Id,Title,Description,author from Articletable", conn); DataSet ds = new DataSet(); da.Fill(ds,"MyTestTable"); return ds.Tables["MyTestTable"]; } } |