Sei sulla pagina 1di 4

code for selecting data from gridview by each row int count = GridView5.Rows.

Count; if (count > 0) { foreach (GridViewRow row in GridView5.Rows) { string no = row.Cells[0].Text; string grp = row.Cells[1].Text; string product = row.Cells[2].Text; string desc = row.Cells[3].Text; string batch = row.Cells[4].Text; string expdate = row.Cells[5].Text; string rate = row.Cells[6].Text; string qty = row.Cells[7].Text; string amt = row.Cells[8].Text; } } code for limiting the enter on text box this.txtsearch.Attributes.Add("OnKeyDown", "return event.keyCode == 13 ? false : true"); code for screen resize public void textsize() { int height; int width; double perwidth; height = Request.Browser.ScreenPixelsHeight; width = Request.Browser.ScreenPixelsWidth; perwidth = (width * 18) / 100; txttblog.Height = height; txttblog.Width = width - Convert.ToInt16(perwidth); } code for selecting item in dropdown box lst = ddlcountry.Items.FindByText(grdreg.SelectedRow.Cells[11].Text); index = ddlcountry.Items.IndexOf(lst); ddlcountry.SelectedIndex = index; button property usesubmitbehaviour=false for hitting button on enter code for blank grid view str = "select * from tempproduct order by no desc"; cmd = new MySqlCommand(str, Classmysql.con); dtp = new MySqlDataAdapter(cmd); ds = new DataSet(); dtp.Fill(ds); if (ds.Tables[0].Rows.Count != 0) { GridView3.DataSource = ds; GridView3.DataBind(); } else { ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());

GridView3.DataSource = ds; GridView3.DataBind(); int columncount = GridView3.Rows[0].Cells.Count; GridView3.Rows[0].Cells.Clear(); GridView3.Rows[0].Cells.Add(new TableCell()); GridView3.Rows[0].Cells[0].ColumnSpan = columncount; GridView3.Rows[0].Cells[0].Text = "No product selected"; } code for highlight text in gridview public string highlighttext(string inputtxt) { foreach (GridViewRow row in grdreg.Rows) { for (int i = 0; i < row.Cells.Count; i++) { if (row.Cells[i].Text.Contains(inputtxt)) { row.Cells[i].BackColor = System.Drawing.Color.LightPink; } } } code for convert value to capital txttupper[i].Text = txttupper[i].Text.ToUpper(); code for redirect page in new tab Response.Write("<script>window.open( '../crm/frmpartylegder. aspx' , '-blank' );</script>"); query for combined search "select * from registration where dt between '" + txtfrom.Text + "' and '" + txtto.Text + "' and ( grp like '%" + txtcombine.Text + "%' or state like '% " + txtcombine.Text + "%' or city like '%" + txtcombine.Text + "%' or area lik e '%" + txtcombine.Text + "%' or producttype like '%" + txtcombine.Text + "%')" "select distinct sno,billdate,clientid,org from `pacecrm`.`bill` where billdate < '2013-02-07'" date formate for mysql db="yyyy-MM-dd" code for converting system date or any date to any formate 1>txtdate.Text = System.DateTime.Now.ToString("yyyy-MM-dd"); 2> DateTime dt = Convert.ToDateTime(grdreg.SelectedRow.Cells[2].Text); str=dt.ToString("yyyy-MM-dd"); txtdate.Text = str; code for finding birthday\ str = "select client from registration where day(dob)='" + dt.Day + "' an d month(dob)='" + dt.Month + "'"; cmd = new MySqlCommand(str, Classmysql.con); dtp = new MySqlDataAdapter(cmd); ds = new DataTable(); dtp.Fill(ds);

foreach (DataRow row in ds.Rows) { TextBox1.Text += row.ItemArray.GetValue(0).ToString() +","; } code for displaing limited char in text box string s = ds.Rows[0]["blogdetail"].ToString(); if (s.Length > 620) { txttblog.Text = s.Substring(0, 620) + " ...."; txttblog.Attributes.Add("style", "overflow :hidden"); } code for highlight text in gridview--reference by aspdotnetsuresh.com header file using System.Text.RegularExpressions; code file public string HighlightText(string inputtxt) { string searchstr = txtsearch.Text; Regex regexp = new Regex(searchstr.Replace(" ", "|").Trim(), RegexOption s.IgnoreCase); return regexp.Replace(inputtxt, new MatchEvaluator(ReplaceKeyWords)); } public string ReplaceKeyWords(Match m) { return ("<span class=highlight>" + m.Value + "</span>"); } aspx file code //head <style type="text1/css"> .GridviewDiv {font-size: 100%; font-family: 'Lucida Grande', 'Lucida Sans Unicod e', Verdana, Arial, Helevetica, sans-serif; color: #303933;} Table.Gridview{border:solid 1px #df5015;} .Gridview th{color:#FFFFFF;border-right-color:#abb079;border-bottom-color:#abb07 9;padding:0.5em 0.5em 0.5em 0.5em;text-align:center} .Gridview td{border-bottom-color:#f0f2da;border-right-color:#f0f2da;padding:0.5e m 0.5em 0.5em 0.5em;} .Gridview tr{color: Black; background-color: White; text-align:left} :link,:visited { color: #DF4F13; text-decoration:none } .highlight {text-decoration: none;color:black;background:yellow;} </style> //body <asp:GridView ID="grdreg" runat="server" AutoGenerateSelectButton="True" onselectedindexchanged="grdreg_SelectedIndexChanged" BorderStyle="Groove" CellPadding="0" AllowPaging="True" Allow Sorting="True" AutoGenerateColumns="False" CssClass="Gr idview" onrowdatabound="grdreg_RowDataBound" > <Columns> <asp:TemplateField HeaderText="SNO"> <ItemTemplate> <asp:Label ID="lblsno" runat="server" Text='<%# Eval("sno") %>'></asp:Label> </ItemTemplate> </asp:TemplateField>

</gridview> code for getting value of label added in gridview protected void grdreg_RowEditing(object sender, GridViewEditEventArgs e ) { int index = e.NewEditIndex; Label lbl = grdreg.Rows[index].FindControl("lblsno") as Label; txtsno.Text = lbl.Text; }

Potrebbero piacerti anche