Thursday, January 16, 2014

How to check internet connection using C#


I just created a small program for detecting internet connection on computer, that will be use for uploading of local database to central server

Here is the sample code

using System.Net;

public static bool CheckForInternetConnection()
        {
            try
            {

                using (var client = new WebClient())
                using (var stream = client.OpenRead("http://google.com.ph"))
                {
                    return true;
                }
            }
            catch
            {
                return false;
            }
        }

Thursday, October 6, 2011

Find Stored Procedure Related to Table in Database

Following code will help to find all the Stored Procedures (SP) which are related to one or more specific tables. sp_help and sp_depends does not always return accurate results.

SELECT DISTINCT so.name
FROM syscomments sc
INNER JOIN sysobjects so ON sc.id=so.id
WHERE sc.TEXT LIKE '%tablename%'

Wednesday, September 7, 2011

How to use modal popup inside the gridview

Here is some code sample on how to use the modal-up inside gridview, here is sample screenshot of my project.

Gridview with Join button that will trigger the modal popup.


Modal popup confirmation after clicking the Join button


The trick to do this is just to add a hidden button to be used as the TargetControlID as you code see in aspx code below:

<asp:Button id="btnShowPopup" runat="server" style="display:none" />
<asp:ModalPopupExtender ID="JoinModal" runat="server" PopupControlID="pnlJoin"
TargetControlID="btnShowPopup" BackgroundCssClass="modalBackground"                                            CancelControlID="bnCancel">
asp:ModalPopupExtender>


Modal popup code:


Gridview code



And from the code behind all you need is to call the ".Show()" method of the modal popup extender.

protected void grdResult_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Join")
            {
                    this.updJoin.Update();// use this if you need to update something inside the modal panel
                    JoinModal.Show();
            }
           
        }