Sunday 24 May 2015

datatable.select (LINQ funda)

private void PopulateGrid(GridView gv, Int32 pageindex, DataSet dsGV)
    {
        try
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            DataRow[] dr = null;

            string exp = "rowno = " + pageindex;
            if (dsGV.Tables[0].Rows.Count > 0)
                dr = dsGV.Tables[0].Select(exp);

            ds = dsGV.Clone();
            foreach (DataRow drr in dr)
                ds.Tables[0].ImportRow(drr);

            gv.DataSource = ds;
            gv.DataBind();

            //following code is written to get current level description from id_member_levels table
            //this is written to avoid join in the main query
            //if we give join in main query in Populate proceure, it affects on the performance of the query.
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (cn.State == ConnectionState.Closed)
                {
                    cn.Open();
                    cm = new OleDbCommand("", cn);
                }
            }

            //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            //{

            //    if (ds.Tables[0].Rows[i]["MM_CURR_LEVEL"].ToString().Equals("0") == false)
            //    {
            //        strSQL = "select ML_DESC from id_member_levels where ml_level = " + ds.Tables[0].Rows[i]["MM_CURR_LEVEL"].ToString();
            //        cm.CommandText = strSQL;
            //        reader = cm.ExecuteReader();
            //        if (reader.Read())
            //            gv.Rows[i].Cells[c_Level].Text = reader["ML_DESC"].ToString();
            //        reader.Close();
            //    }
            //    else
            //        gv.Rows[i].Cells[c_Level].Text = "NA";
            //}

            if (cn.State == ConnectionState.Open)
            {
                cm.Dispose();
                cn.Close();
            }
        }
        catch (Exception ex) { lblError.Text = ex.Message; }
        finally { }
    }

Friday 8 May 2015

Update textbox data on click of button on another page with telerik rad window



dark is parent window

 modal is individual page which is opened with telerik rad window

on click of save on modal page, we need to update parent page's benefeciary name also


On parent aspx
---------------------------------------------------
<%@ MasterType VirtualPath="~/Site.master" %>


function OnSubItemClose(oWnd, args) {
       if (args._argument != null) {
           console.log(args);
       }
   }



<telerik:RadWindowManager runat="server" ID="radmanager">
        <Windows>
            <telerik:RadWindow ID="ListDialog" runat="server" ReloadOnShow="true" ShowContentDuringLoad="false" Width="500px" Height="400px"
                Modal="true" VisibleStatusbar="false" ShowOnTopWhenMaximized="true" AutoSize="false"
                EnableViewState="false" KeepInScreenBounds="false" Behaviors="Close"
                VisibleTitlebar="true" VisibleOnPageLoad="false">
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>


<asp:TextBox ID="txt_beneficiary" runat="server"  ClientIDMode="Static" />

<asp:Button ID="btnbeneficiary" Text="..." runat="server"
                                onclick="btnbeneficiary_Click" />


On parent page code
----------------------------
private void SetWindow(string navurl, string onclientclose)
    {
        radmanager.Windows.Clear();
        ListDialog.NavigateUrl = navurl;
        ListDialog.VisibleOnPageLoad = true;
        ListDialog.OnClientClose = onclientclose;

        radmanager.Windows.Add(ListDialog);
    }
    protected void btnbeneficiary_Click(object sender, EventArgs e)
    {
        if (!ddl_CenterList.Enabled)
        {
            SetWindow("~/cp_beneficiary.aspx?Memid=" + ViewState["MemberID"].ToString(), "OnSubItemClose");
        }
        else
        {
            lblError.Text = "Please take appointment first.";
        }
    }


on modal page aspx
---------------------------------
<%@ MasterType VirtualPath="~/Site.master" %>


 <script type="text/javascript">

        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow)
                oWindow = window.radWindow;
            else if (window.frameElement.radWindow)
                oWindow = window.frameElement.radWindow;
            return oWindow;
        }

        function UpdateName() {
            GetRadWindow().BrowserWindow.document.getElementById("txt_beneficiary").value = <%= txtBenName.ClientID%>.value;
        }
    </script>

<asp:Button Text="Save" runat="server" ID="btnSave" onclick="btnSave_Click" OnClientClick="UpdateName(); return true;" />