Wednesday, August 20, 2025

How to add dummy data to datatable with multiple columns

 DataTable dt = new DataTable("DummyData");

        dt.Columns.Add("Id", typeof(int));

        dt.Columns.Add("Name", typeof(string));

        dt.Columns.Add("City", typeof(string));



        DataTable dt1 = new DataTable("DummyData");

        dt1.Columns.AddRange(new DataColumn[] {

        new DataColumn("Id", typeof(int)),

        new DataColumn("Name", typeof(string)),

        new DataColumn("City", typeof(string))

    });


        dt.Rows.Add(1, "John Doe", "New York");

        dt.Rows.Add(2, "Jane Smith", "London");

        dt.Rows.Add(3, "Peter Jones", "Paris");

//or

 //  DataRow newRow = dt.NewRow();

    newRow["Id"] = 4;

   // newRow["Name"] = "Alice Brown";

    //newRow["City"] = "Tokyo";

    //dt.Rows.Add(newRow);

        GridView1.DataSource = dt;

        GridView1.DataBind();

How to add dummy data to datatable or gridview with array of string

   string[] myString1 = { "sum", "minus"};



        

        DataTable dt = new DataTable();

        dt.Columns.Add("Name", typeof(string));


        foreach (string item in myString1)

        {

            System.Data.DataRow row = dt.NewRow();

            row["Name"] = item; // Assign the string to the column

            dt.Rows.Add(row); // Add the row to the DataTable

        }


        

        GridView1.DataSource = dt;

        GridView1.DataBind();

How to use same mouse for computer and mobile

 >To use this, you have to first connect these devices by bluetooth

> Second you have to install GlideX, Phone mirror , Remote mouse, PC remote to your both devices

How to use two displays or two monitors with one mouse

>Right click on desktop

 >Go to display settings

> and there is option of "Duplicate these videos", "Extend these videos" and click on Extend these videos , it will work for both monitors.


and use "microsoft without borders" for two different computers and having same mouse.

Friday, August 15, 2025

How to open binary file from database on browser- only display

 byte[] bytes =   file.FileData;

Response.Clear();

    Response.ContentType = file.ContentType;

Response.BinaryWrite(bytes);


https://www.aspsnippets.com/questions/206135/Open-Show-Base64-PDF-data-in-new-window-Tab-using-C-and-VBNet-in-ASPNet/

How to open new window with width and height - using window.open

  <a href="#" onclick="MyWindow=window.open('https://www.aspsnippets.com/Articles/660/Display-image-from-database-in-Image-control-without-using-Generic-Handler-in-ASPNet/','MyWindow','width=600,height=300'); ">click to open new window</a>

How to view the image in browser from database - binary image from database - asp.net

  string alert1 = "var image = new Image();";

        alert1+= "image.src='data:image/jpg;base64,"+ Convert.ToBase64String(bytes)+"';";

        alert1 += "var w = window.open('');";

              alert1+= "w.document.write(image.outerHTML);";


           ScriptManager.RegisterStartupScript(this, this.GetType(), "OpenNewTabScript", alert1, true);


ref:-https://stackoverflow.com/questions/27798126/how-to-open-the-newly-created-image-in-a-new-tab

Thursday, August 14, 2025

System.InvalidOperationException: ExecuteScalar: Connection property has not been initialized.

 This error comes when you write below code:-


using (SqlCommand cmd=new SqlCommand("SELECT TOP 1 [FileID]  FROM [UploadFiles] order by Fileid desc"))


and not passed con as second parameter in SqlCommand. Use below code

using (SqlCommand cmd=new SqlCommand("SELECT TOP 1 [FileID]  FROM [UploadFiles] order by Fileid desc", con))


also you have to add below line

cmd.CommandType = System.Data.CommandType.Text;

How to display binary images from database - How to view images from database - view binary images - asp.net c# - How to download file from database

protected void FetchImage(object sender, EventArgs e)

{

    string id = ddlImages.SelectedItem.Value;

    Image1.Visible = id != "0";

    if (id != "0")

    {

        byte[] bytes = (byte[])GetData("SELECT Data FROM tblFiles WHERE Id =" + id).Rows[0]["Data"];

        string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);

        Image1.ImageUrl = "data:image/png;base64," + base64String;

    }

}


ref:- https://www.aspsnippets.com/Articles/660/Display-image-from-database-in-Image-control-without-using-Generic-Handler-in-ASPNet/ 

How to run background music in website - HTML

 https://www.tutorialspoint.com/how-to-add-background-music-to-your-web-page

Tuesday, August 12, 2025

How to download file using binarywrite function and download file from url link - using webclient function

  protected void btnClickMe_Click(object sender, EventArgs e)

    {

                WebClient client = new WebClient();

        byte[] bytes = client.DownloadData("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgahqj6mU5OTtB-PLGl36tvYYv02OuXuR__pTakG-Y8dBc36TZaSboLga6RwM8DJUQKAwJ_sSjkp-4nhW1udweEejazbrZ50z2cb1ynJgIaZNBlrSIy827bc_5iY6UesB4/s220/WIN_20220808_12_53_18_Pro.jpg");

        Response.Clear(); //This must be add ,without this the file that you save will not be open

        Response.AddHeader("content-disposition", "attachment; filename=1.jpg"); 

         


 //Response.ContentType = System.Net.Mime.MediaTypeNames.Image.Jpeg; 


        //"application/octet-stream"; 


        Response.BinaryWrite(bytes);

        Response.Flush();

        Response.End();

    }


Note:-         Response.Clear(); //This must be add ,without this the file that you save will not be open

Friday, August 8, 2025

How to t change text font background of Menu Under Header of Blogger - Tabs of blogger - pages gadget of blogger

> Click on theme

>Click on Customize

>Click on advance

>Select tabs from dropdown list

> And you can change font size, font , background

>and click on save


Also you can change font size and font of other gadgets

Thursday, August 7, 2025

How to convert div to pdf using itextsharp asp.net - C# - Simplest and less code

First you have to download itextsharp.dll and itextsharp.pdfa.dll files and  you have to give the font size as below because in some case it will give error that font size is small.

 <form id="form1" runat="server">

        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

    <div id="mainDiv" runat="server">

        

        <asp:Label runat="server" Text="Test" Font-Bold="true" Font-Size="13px" />

        <br />


        <asp:Label runat="server" Text="E-Admit Card" Font-Bold="true" Font-Size="13px" />

        <br />


        <table border="1">

            <tr>

                <td>

                    <asp:Label runat="server" Text="Date Of Test:" Font-Size="13px" />

                </td>

                <td>

                    <asp:Label runat="server" Text="20/11/2024" Font-Size="13px" />

                </td>

            </tr>

        </table>

        

    </div>

        <asp:Button ID="Button1" runat="server" Text="Print" OnClick="Button1_Click" />

</form>


===========================

 protected void Button1_Click(object sender, EventArgs e)

    {

        Response.ContentType = "application/pdf";

        Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");

        Response.Cache.SetCacheability(HttpCacheability.NoCache);

        StringWriter stringWriter = new StringWriter();

        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

        

        mainDiv.RenderControl(htmlTextWriter);

        StringReader stringReader = new StringReader(stringWriter.ToString());

        Document Doc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);

        HTMLWorker htmlparser = new HTMLWorker(Doc);

        PdfWriter.GetInstance(Doc, Response.OutputStream);


        Doc.Open();

        htmlparser.Parse(stringReader);

        Doc.Close();

        Response.Write(Doc);

        Response.End();

    }