Sunday, November 27, 2011

Get all words starts from @

We can use following regrular expression for fetch all words start with @

Regex MyList = new Regex(@"@(?<vKey>[\w\.]+)");//

Sample code :

<string> NameList = new List<string>();Regex MyList = new Regex(@"@(?<vKey>[\w\.]+)");//if this is not working than put slash before "@"

MatchCollection myMatches = MyList.Matches(TextBoxSQLQuery.Text.Trim(), 0);StringBuilder sb = new StringBuilder();string syntax = TextBoxEbaseParameter.Text.Trim() + "(\"@";foreach (Match myMatch in myMatches)string varName = myMatch.Groups["vKey"].Value;}

Mahesh Kumar Sharma

Sunday, November 6, 2011

How to get HTML of control before render event

Suppose we have to show grid from ajax request than we can bind grid by data base and get its HTML structure. Code is bellow
GridView gv = new GridView();
      gv.AutoGenerateColumns = true;         //Your Logic to fill dataset/datatable       
      DataTable dt = new DataTable();
      dt.Columns.Add(new DataColumn("Index"));
      dt.Columns.Add(new DataColumn("Name"));
      for (int i = 0; i < 10; i++) { DataRow row = dt.NewRow(); row["Index"] = i; row["Name"] = "dummyData" + i.ToString(); dt.Rows.Add(row); }
      //bind the gridview        
      gv.DataSource = dt;
      //get the rendered HTML       
      StringBuilder sb = new StringBuilder();
      StringWriter writer = new StringWriter(sb);
      HtmlTextWriter txt = new HtmlTextWriter(writer);
      return sb.ToString();