Thursday 29 March 2018

Merge Gridview Rows with same values in cells using Asp.net and C#

///////////////

   protected void GV_PerformanceObjective_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        for (int i = GV_PerformanceObjective.Rows.Count - 2; i >= 0; i--)
        {
            GridViewRow row = GV_PerformanceObjective.Rows[i];
            GridViewRow preRow = GV_PerformanceObjective.Rows[i + 1];

            string currRow = ((LinkButton)row.FindControl("lbtn_EditObjective")).Text.Trim();
            string prevRow = ((LinkButton)preRow.FindControl("lbtn_EditObjective")).Text.Trim();

            if (currRow == prevRow)
            {
                row.Cells[0].RowSpan = preRow.Cells[0].RowSpan < 2 ? 2 : preRow.Cells[0].RowSpan + 1;
                preRow.Cells[0].Visible = false;
            }
        }

    }




Thursday 22 March 2018

Rotate text in ms excel from HTML table using style inside table

///////////////////////////
style-

<style>
mso-rotate: 40; /where 40 is degree/
</style>



<table >
        <thead>
            <tr>
                <th colspan="2" rowspan="2" style="background-color: aqua; mso-rotate: 40;">
                    Column 0
                </th>
                <th rowspan="2" style="mso-rotate: 90;">
                    Column 1
                </th>
                <th colspan="2">
                    Column 2
                </th>
            </tr>
            <tr>
                <th>
                    Column 2a
                </th>
                <th>
                    Column 2b
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th rowspan="2">
                    Row 1
                </th>
                <th style="mso-rotate: 60;">
                    Row 1a
                </th>
                <td>
                    123
                </td>
                <td>
                    456
                </td>
                <td>
                    789
                </td>
            </tr>
            <tr>
                <th>
                    Row 1b
                </th>
                <td class="rotate" style="mso-rotate: 90;">
                    123
                </td>
                <td>
                    456
                </td>
                <td>
                    789
                </td>
            </tr>
            <tr>
                <th colspan="2" style="mso-rotate: -90;">
                    Row 2
                </th>
                <td>
                    123
                </td>
                <td>
                    456
                </td>
                <td>
                    789
                </td>
            </tr>
        </tbody>
    </table>


Enable/Disable ASP.Net Required Validator on Client Side using JavaScript or jQuery

///////////////////
JAVASCRIPT-

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $(document).on("click""#CheckBoxValidator1"function () {
        var valEmail = $("[id*=RequiredValidator1]");
        ValidatorEnable(valEmail[0], $(this).is(":checked"));
    });
</script>


//////////////////
HTML-


<asp:TextBox ID="txt_CheckValidator" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredValidator1" ControlToValidate="txtEmail"
    runat="server" ErrorMessage="*Required" ForeColor="Red" ValidationGroup="Group2" />
<br />
Enable Validation:
<input type="checkbox" id="CheckBoxValidator1" checked="checked" />
<br />
<asp:Button ID="Button1" Text="Submit" runat="server" ValidationGroup="Group2" />



Sunday 18 March 2018

Convert Datetime in AM/PM format using sql query

/////////////

select CONVERT(VARCHAR(12), getdate(), 103) + ' ' + LTRIM(RIGHT(CONVERT(CHAR(20), getdate(), 22), 11))

Friday 16 March 2018

Multiple column pivot in sql server using sql query

/////////////// Function using CROSS APPLY


DECLARE @Temp_Table TABLE (Branch varchar(9), Category varchar(9), Sales INT,Stock INT,Target INT)

INSERT INTO @Temp_Table (Branch, Category, Sales, Stock,Target)
VALUES
    ( 'Gurgaon', 'Spanel', 10,4,15),
    ( 'Gurgaon', 'AC', 11,7,14),
    ( 'Gurgaon', 'Ref', 7,2,10),
    ( 'Delhi', 'Spanel',20,4,17),
    ( 'Delhi', 'AC', 5,2,12),
    ( 'Delhi', 'Ref', 10,12,22)

---------- Check Table Value before pivot
select * from @Temp_Table

---------- Check Table Value After pivot

 Select BRANCH,COL,[Spanel],[AC],[Ref] from (
    select Branch,Category,COL,VAL from @Temp_Table  CROSS APPLY (VALUES ('Sales',Sales),  ('Stock',Stock), ('Target',Target))CS (COL,VAL))T
    PIVOT (MAX(VAL) FOR Category IN ([Spanel],[AC],[Ref]))PVT



Wednesday 14 March 2018

MS Captcha not working with IIS

////////////////////
Step 1. Create Application pool for project and set -

Managed Pipeline Mode - Classic

Step 2. Set Handler in web.config file inside the system.web -

<system.web>   
    <httpHandlers>
      <add verb="GET" path="CaptchaImage.axd" type="MSCaptcha.CaptchaImageHandler, MSCaptcha"/>

</system.web>    

Step 3. Set allow for the users inside the location tag 

<location path="CaptchaImage.axd">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>

  </location>


Replace Server from response header from IIS7 + in asp.net web.config

/////////////////

Step 1.  Download URLRewrite from microsoft server
 link for

·         English: WebPI / x86 / x64

for more details please visit at -
https://www.iis.net/downloads/microsoft/url-rewrite

Step 2.


<system.webServer>
    <rewrite>
      <outboundRules>
        <rule name="Strip Headers">
          <match serverVariable="RESPONSE_SERVER" pattern=".*" />
          <action type="Rewrite" value="ACIWRM" replace="true" />
          <conditions>
          </conditions>
        </rule>
      </outboundRules>
    </rewrite>
  </system.webServer>

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...