Posts

Showing posts from July, 2021

Export GridView to Excel

            string attachment = "attachment; filename=registration.xls";         Response.ClearContent();         Response.AddHeader("content-disposition", attachment);         Response.ContentType = "application/ms-excel";         StringWriter sw = new StringWriter();         HtmlTextWriter htw = new HtmlTextWriter(sw);         HttpContext.Current.Response.Write("<br>");         HtmlForm frm = new HtmlForm();         GridView1.Parent.Controls.Add(frm);         frm.Attributes["runat"] = "serve";         frm.Controls.Add(GridView1);         frm.RenderControl(htw);         Response.Write(sw.ToString());         Response.End();

Dynamic Data Grid View

protected void Button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[3]  { // typeof() is used for dynamic data type allocation new Column("id",typeof(int)), new Column("Name",typeof(string)), new Column("City",typeof(string)) }); dt.Rows.Add(1,"Chitransh","Jabalpur"); dt.Rows.Add(2,"Shashank","Bhopal"); dt.Rows.Add(3,"Ananya","Delhi"); GridView1.Datasource = dt; GridView1.DataBind(); }

Select the RadioButtonList Item Using User Input

  CODE:- RadioButtonList1.Items.FindByText(dr["column_name"].ToString()).Selected== true; --------------------------------------------------------------------------------------------------------------------- Implementation:-   protected void Button3_Click(object sender, EventArgs e)     {         myclass m1 = new myclass();         string cs = m1.connection(); // calling function inside a class          cn = new SqlConnection(cs);         cn.Open();         string q = "select * from chitransh_table where name='"+TextBox5.Text+"'";         cm = new SqlCommand(q, cn);         dr = cm.ExecuteReader();         if (dr.Read())         {             RadioButtonList1.Items.FindByText(dr["city"].ToString()).Selected = true;         }   ...

Break the Control Refreshment

  Example:- <form>   <asp:ScriptManager> </asp:ScriptManager> <asp:UpdatePanel> <ContentTemplate> <asp:DropDownList>// place any Drop down list  <asp:ListItem> //Items </asp:ListItem> </asp: DropDownList > </ContentTemplate> </asp:UpdatePanel> </form>