Tuesday, 29 October 2013

grid having button click event code behind retrive grid selected checkbox values



            string ids = string.Empty;
            ids = (from GridViewRow gvSingleSavingsBookRow in grvVendorProperties.Rows
                   let rowSelected = (CheckBox)gvSingleSavingsBookRow.FindControl("chkVendorProperties")
                   let myId = (HiddenField)gvSingleSavingsBookRow.FindControl("HiddenEntityID")
                   where (null != rowSelected) && (null != myId)
                         && rowSelected.Checked
                   select myId).Aggregate(ids, (current, myId) =>
                                string.Format("{0}{1}{2}", current, myId.Value.Trim(), ","));



-----------------------------------------------------------------------------

for (int rowIndex = 0; rowIndex < grvVendorProperties.Rows.Count; rowIndex++)
            {
                TextBox txtExpenseAccount = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtExpenseAccount");
                TextBox txtInitialBalance = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtInitialBalance");
                Button btnExpenseAccount = (Button)grvVendorProperties.Rows[rowIndex].FindControl("btnExpenseAccount");
                TextBox txtEffectiveDate = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtEffectiveDate");
                TextBox txtReceiptAccount = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtReceiptAccount");
                Button btnReceiptAccount = (Button)grvVendorProperties.Rows[rowIndex].FindControl("btnReceiptAccount");

                CheckBox chk = (CheckBox)grvVendorProperties.Rows[rowIndex].FindControl("chkVendorProperties");

                if (chk.Checked == true)
                {
                    chk.Checked = true;
                    txtExpenseAccount.Enabled = true;
                    txtInitialBalance.Enabled = true;
                    btnExpenseAccount.Enabled = true;
                    txtEffectiveDate.Enabled = true;
                    txtReceiptAccount.Enabled = true;
                    btnReceiptAccount.Enabled = true;
                }
                else
                    chk.Checked = false;
            }

grid row having button and after click particulare row button event find entire grid checkbox selected rows only using linq list

     
  List<int> listIndex = CheckedRows.AsEnumerable().Select(f => f.RowIndex).ToList();

            foreach (int rowIndex in listIndex)
            {
                TextBox txtExpenseAccount = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtExpenseAccount");
                TextBox txtInitialBalance = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtInitialBalance");
                Button btnExpenseAccount = (Button)grvVendorProperties.Rows[rowIndex].FindControl("btnExpenseAccount");
                TextBox txtEffectiveDate = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtEffectiveDate");
                TextBox txtReceiptAccount = (TextBox)grvVendorProperties.Rows[rowIndex].FindControl("txtReceiptAccount");
                Button btnReceiptAccount = (Button)grvVendorProperties.Rows[rowIndex].FindControl("btnReceiptAccount");

                txtExpenseAccount.Enabled = true;
                txtInitialBalance.Enabled = true;
                btnExpenseAccount.Enabled = true;
                txtEffectiveDate.Enabled = true;
                txtReceiptAccount.Enabled = true;
                btnReceiptAccount.Enabled = true;

            }




Monday, 28 October 2013

Grid view button click dont want to referesh grid

 <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
            <ContentTemplate>
  <asp:Button ID="btnExpenseAccount" runat="server" CssClass="button_small_tgrid" Text="..."
                                                    Enabled="false" OnClick="btnExpenseAccount_Click" />
 </ContentTemplate>
 </asp:UpdatePanel>

protected void btnExpenseAccount_Click(object sender, EventArgs e)
        {
Button btn = (Button)sender;
UpdatePanel1.Triggers.Add(new AsyncPostBackTrigger { ControlID = btn.UniqueID, EventName = "click" });
}

Friday, 25 October 2013

when mouse over to the link it will show pointer

 <asp:Label ID="lnkSelectAll"  runat="server" Text="Select All" Style="cursor: pointer" >
</asp:Label>

Gridview column bind with substring and ... if exceed column width limit and showing tooltip with entirecolumn text

 <asp:Label ID="lblProperty" runat="server" Text='<%# Eval("PropertyName").ToString().Length <= 15 ?                Eval("PropertyName") : Eval("PropertyName").ToString().Substring(0,15)+"..." %>'
             ToolTip='<%# Eval("PropertyName") %>' Visible="true"></asp:Label>



we also can do this substring column by using row data bound event below code explain how we can do this

  protected void grvVendorProperties_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {

     Label lblName = (Label)e.Row.FindControl("lblProperty");
                string strName = lblName.Text;
                if (strName.Length > 7)
                {
                    lblName.Text = strName.Substring(0, 7) + "..";
                    lblName.ToolTip = strName;
                }
}
}

Grid view check box all script

 //********************Check box all script*******************************
    function GetChecked() {
        var grdView = $('#<%= grvVendorProperties.ClientID %>');
        var tr = $('#<%= grvVendorProperties.ClientID %>').find('tr');
        $('#<%= grvVendorProperties.ClientID %>').find('tr').find('input:checkbox[name$=chkVendorProperties]').each(function () {
            if (this.checked) {
                $(this).parents('tr').find('[id$=txtEffectiveDate]').datepicker('enable');
                $(this).parents('tr').find('[id$=btnExpenseAccount]').attr("disabled", "");
                $(this).parents('tr').find('[id$=txtExpenseAccount]').attr("disabled", "");
                $(this).parents('tr').find('[id$=txtInitialBalance]').attr("disabled", "");
                $(this).parents('tr').find('[id$=txtEffectiveDate]').attr("disabled", "");
                $(this).parents('tr').find('[id$=txtReceiptAccount]').attr("disabled", "");
                $(this).parents('tr').find('[id$=btnReceiptAccount]').attr("disabled", "");
            }
            else {
                $(this).parents('tr').find('[id$=txtEffectiveDate]').datepicker('disable');
                $(this).parents('tr').find('[id$=btnExpenseAccount]').attr("disabled", "disabled");
                $(this).parents('tr').find('[id$=txtExpenseAccount]').attr('disable', 'disabled');
                $(this).parents('tr').find('[id$=txtInitialBalance]').attr("disable", "disabled");
                $(this).parents('tr').find('[id$=txtEffectiveDate]').attr("disable", "disabled");
                $(this).parents('tr').find('[id$=txtReceiptAccount]').attr("disable", "disabled");
                $(this).parents('tr').find('[id$=btnReceiptAccount]').attr("disable", "disabled");

            }

        });
    }


    function GetCheckStatus() {
        var srcControlId = event.srcElement.id;
        var txtEffectiveDate = event.srcElement.id.replace('chkVendorProperties', 'txtEffectiveDate');
        var txtInitialBalance = event.srcElement.id.replace('chkVendorProperties', 'txtInitialBalance');
        var txtExpenseAccount = event.srcElement.id.replace('chkVendorProperties', 'txtExpenseAccount');
        var txtReceiptAccount = event.srcElement.id.replace('chkVendorProperties', 'txtReceiptAccount');
        var btnExpenseAccount = event.srcElement.id.replace('chkVendorProperties', 'btnExpenseAccount');
        var btnReceiptAccount = event.srcElement.id.replace('chkVendorProperties', 'btnReceiptAccount');
        if (document.getElementById(srcControlId).checked) {
            //   $('#ctl00_ctl00_plcHolderHomemaster_plcHolderSubModuleData_VendorProperty_grvVendorProperties_ctl05_txtEffectiveDate').datepicker('enable');
            //  $(txtEffectiveDate).datepicker('enable');
            //$("[id$='txtEffectiveDate']").datepicker("enable");

            document.getElementById(txtEffectiveDate).disabled = false;
            document.getElementById(txtInitialBalance).disabled = false;
            document.getElementById(txtExpenseAccount).disabled = false;
            document.getElementById(txtReceiptAccount).disabled = false;
            document.getElementById(btnExpenseAccount).disabled = false;
            document.getElementById(btnReceiptAccount).disabled = false;


        }
        else {
            /// $('#ctl00_ctl00_plcHolderHomemaster_plcHolderSubModuleData_VendorProperty_grvVendorProperties_ctl05_txtEffectiveDate').datepicker('disable');
            //$(txtEffectiveDate).datepicker('disable');
            document.getElementById(txtEffectiveDate).disabled = true;
            document.getElementById(txtInitialBalance).disabled = true;
            document.getElementById(txtExpenseAccount).disabled = true;
            document.getElementById(txtReceiptAccount).disabled = true;
            document.getElementById(btnExpenseAccount).disabled = true;
            document.getElementById(btnReceiptAccount).disabled = true;
        }
    }


    function selectAll(checked) {

        var txtExpenseAccount = $("[id$='txtExpenseAccount']");
        var btnExpenseAccount = $("[id$='btnExpenseAccount']");
        var txtInitialBalance = $("[id$='txtInitialBalance']");
        var txtEffectiveDate = $("[id$='txtEffectiveDate']");
        var txtReceiptAccount = $("[id$='txtReceiptAccount']");
        var btnReceiptAccount = $("[id$='btnReceiptAccount']");
        $("[id$='txtEffectiveDate']").datepicker("enable");

        if (checked) {
            $('input:checkbox[name$=chkVendorProperties]').each(function () {
                txtExpenseAccount.removeAttr("disabled");
                btnExpenseAccount.removeAttr("disabled");
                txtInitialBalance.removeAttr("disabled");
                txtEffectiveDate.removeAttr("disabled");
                txtReceiptAccount.removeAttr("disabled");
                btnReceiptAccount.removeAttr("disabled");
                $(this).attr('checked', 'checked');
            });
        }
    }


    function UnselectAll(checked) {
        var txtExpenseAccount = $("[id$='txtExpenseAccount']");
        var btnExpenseAccount = $("[id$='btnExpenseAccount']");
        var txtInitialBalance = $("[id$='txtInitialBalance']");
        var txtEffectiveDate = $("[id$='txtEffectiveDate']");
        var txtReceiptAccount = $("[id$='txtReceiptAccount']");
        var btnReceiptAccount = $("[id$='btnReceiptAccount']");
        $("[id$='txtEffectiveDate']").datepicker("disable");
        if (checked) {
            $('input:checkbox[name$=chkVendorProperties]').each(
                    function () {

                        txtExpenseAccount.attr("disabled", "disabled");
                        btnExpenseAccount.attr("disabled", "disabled");
                        txtInitialBalance.attr("disabled", "disabled");
                        txtEffectiveDate.attr("disabled", "disabled");
                        txtReceiptAccount.attr("disabled", "disabled");
                        btnReceiptAccount.attr("disabled", "disabled");
                        $(this).removeAttr('checked');
                    });
        }
    }
    //********************Check box all script*******************************

grid view row button click enable disable entire grid textbox,buttons if checkbox checked or unchecked

 
        protected void btnExpenseAccount_Click(object sender, EventArgs e)
        {
 ScriptManager.RegisterStartupScript(this, GetType(), "key1", string.Format("GetChecked();"), true);
}


----------------------------------------------------------------------------


<script type="text/javascript">
 function GetChecked() {
            var grdView = $('#<%= grvVendorProperties.ClientID %>');
        var tr = $('#<%= grvVendorProperties.ClientID %>').find('tr');
        $('#<%= grvVendorProperties.ClientID %>').find('tr').find('input:checkbox[name$=chkVendorProperties]').each(function () {
            if (this.checked) {
                $(this).parents('tr').find('[id$=txtEffectiveDate]').datepicker('enable');
                $(this).parents('tr').find('[id$=btnExpenseAccount]').attr("disabled", "");
                $(this).parents('tr').find('[id$=txtExpenseAccount]').attr("disabled", "");
                $(this).parents('tr').find('[id$=txtInitialBalance]').attr("disabled", "");
                $(this).parents('tr').find('[id$=txtEffectiveDate]').attr("disabled", "");
                $(this).parents('tr').find('[id$=txtReceiptAccount]').attr("disabled", "");
                $(this).parents('tr').find('[id$=btnReceiptAccount]').attr("disabled", "");
            }
            else {
                $(this).parents('tr').find('[id$=txtEffectiveDate]').datepicker('disable');
                $(this).parents('tr').find('[id$=btnExpenseAccount]').attr("disabled", "disabled");
                $(this).parents('tr').find('[id$=txtExpenseAccount]').attr('disable', 'disabled');
                $(this).parents('tr').find('[id$=txtInitialBalance]').attr("disable", "disabled");
                $(this).parents('tr').find('[id$=txtEffectiveDate]').attr("disable", "disabled");
                $(this).parents('tr').find('[id$=txtReceiptAccount]').attr("disable", "disabled");
                $(this).parents('tr').find('[id$=btnReceiptAccount]').attr("disable", "disabled");
             
            }

        });
   }

</script>

Grid select all check box and unselect all check box

  <asp:Label ID="lnkSelectAll" runat="server" Text="Select All" CssClass="graylink_13"
onclick="selectAll(this);" ToolTip="Select All" Font-Underline="false" ClientIDMode="Static" ForeColor="Black"> </asp:Label>
<asp:Label ID="lnkUnSelectAll" runat="server" Text="Select None" CssClass="graylink_13"
  onclick="UnselectAll(this);" ToolTip="Select None" Font-Underline="false" ClientIDMode="Static" ForeColor="Black" />
---------------------------------------------------------------------------

<script type="text/javascript">

  function selectAll(checked) {
 
       var txtExpenseAccount = $("[id$='txtExpenseAccount']");
        var btnExpenseAccount = $("[id$='btnExpenseAccount']");
        var txtInitialBalance = $("[id$='txtInitialBalance']");
        var txtEffectiveDate = $("[id$='txtEffectiveDate']");
        var txtReceiptAccount = $("[id$='txtReceiptAccount']");
        var btnReceiptAccount = $("[id$='btnReceiptAccount']");
        $("[id$='txtEffectiveDate']").datepicker("enable");

        if (checked) {
            $('input:checkbox[name$=chkVendorProperties]').each(function () {
                        txtExpenseAccount.removeAttr("disabled");
                        btnExpenseAccount.removeAttr("disabled");
                        txtInitialBalance.removeAttr("disabled");
                        txtEffectiveDate.removeAttr("disabled");
                        txtReceiptAccount.removeAttr("disabled");
                        btnReceiptAccount.removeAttr("disabled");
                        $(this).attr('checked', 'checked');
                    });
        }
    }


    function UnselectAll(checked) {
        var txtExpenseAccount = $("[id$='txtExpenseAccount']");
        var btnExpenseAccount = $("[id$='btnExpenseAccount']");
        var txtInitialBalance = $("[id$='txtInitialBalance']");
        var txtEffectiveDate = $("[id$='txtEffectiveDate']");
        var txtReceiptAccount = $("[id$='txtReceiptAccount']");
        var btnReceiptAccount = $("[id$='btnReceiptAccount']");
        $("[id$='txtEffectiveDate']").datepicker("disable");
        if (checked) {
            $('input:checkbox[name$=chkVendorProperties]').each(
                    function () {
                     
                        txtExpenseAccount.attr("disabled", "disabled");
                        btnExpenseAccount.attr("disabled", "disabled");
                        txtInitialBalance.attr("disabled", "disabled");
                        txtEffectiveDate.attr("disabled", "disabled");
                        txtReceiptAccount.attr("disabled", "disabled");
                        btnReceiptAccount.attr("disabled", "disabled");
                        $(this).removeAttr('checked');
                    });
        }
    }

</script>

jquery Date picker control enable and disable call it on ready and add_endRequest function

    function datpickerenabledisable() {
        $("[id$=chkVendorProperties]").each(function () {
            $(this).click(function () {
                if (this.checked) {
                    $(this).parents('tr').find('[id$=txtEffectiveDate]').datepicker('enable');
                }
                else {
                    $(this).parents('tr').find('[id$=txtEffectiveDate]').datepicker('disable');
                }
            });
        });
    }

Gridview row having button and button click event enable disabling grid view textboxes

 protected void btnExpenseAccount_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            GridViewRow grv = (GridViewRow)btn.NamingContainer;
            int index = grv.RowIndex;
            TextBox txtExpenseAccount = (TextBox)grvVendorProperties.Rows[index].FindControl("txtExpenseAccount");
            TextBox txtInitialBalance = (TextBox)grvVendorProperties.Rows[index].FindControl("txtInitialBalance");
            Button btnExpenseAccount = (Button)grvVendorProperties.Rows[index].FindControl("btnExpenseAccount");
            TextBox txtEffectiveDate = (TextBox)grvVendorProperties.Rows[index].FindControl("txtEffectiveDate");
            TextBox txtReceiptAccount = (TextBox)grvVendorProperties.Rows[index].FindControl("txtReceiptAccount");
            Button btnReceiptAccount = (Button)grvVendorProperties.Rows[index].FindControl("btnReceiptAccount");
            txtExpenseAccount.Enabled = true;
            txtInitialBalance.Enabled = true;
            btnExpenseAccount.Enabled = true;
            txtEffectiveDate.Enabled = true;
            txtReceiptAccount.Enabled = true;
            btnReceiptAccount.Enabled = true;

 }

Thursday, 3 October 2013

MaskedEdit "backspace" and delete problem with safari and chrome -- here's the fix!

the fix is easy. in the current source code of MaskedEditBehavior.js about line 890 you have this:


if (Sys.Browser.agent == Sys.Browser.InternetExplorer || evt.type == "keypress")  
    {
        if (scanCode == 8) // BackSpace
the code should be
if (Sys.Browser.agent == Sys.Browser.InternetExplorer || evt.type == "keydown")  
    {
        if (scanCode == 8) // BackSpace
     ...