Monday, 28 July 2014

Radio buttons and label to display in same line

HTML

 <fieldset style="width:100%"><legend>Duplicates</legend>
                <asp:RadioButton runat="server" ID="rbtn_over" GroupName="Imp" Text="Overwrite" style=" display:inline;" />
               <br /><br />
                <asp:RadioButton runat="server" ID="rbtn_skip" GroupName="Imp" Text="Skip" />               
                
                <br /><br />
                <asp:CheckBox runat="server" ID="chk1" Text="Checkbox1" />
                <br /><br />
                <asp:CheckBox runat="server" ID="CheckBox1" Text="Checkbox1" />

                </fieldset>



//CSS

input[type=radio], input.radio { float:left; clear:none; margin: 2px 8px 0 2px; }
input[type=checkbox], input.checkbox { float:left; clear:none; margin: 2px 8px 0 2px; }


//Result




Tuesday, 22 July 2014

Show alert Messages using AjaxPopupEx. in asp.net using jquery


//Modalpopup

<asp:ModalPopupExtender ID="ModalAlert" runat="server" TargetControlID="hdn_alertmodal" BehaviorID="ModalAlertB"
                PopupControlID="pnl_alert" CancelControlID="btn_cancelalert" BackgroundCssClass="modalBackground">

            </asp:ModalPopupExtender>

//Panel

<asp:HiddenField ID="hdn_alertmodal" runat="server" />
            <asp:Panel ID="pnl_alert" runat="server" Style="display: none;" class="modalPopup"
                Width="345px">
                <div style="padding: 0 0 10px 0;">
                    <div class="header">
                        Alert !</div>
                    <div style="width: 332px; text-align: center" class="body">
                        <div style="width: 100%; height: 8px;">
                        </div>
                        <asp:Label ID="lbl_messages" runat="server" CssClass="LabelHeader" Font-Bold="True"
                            Font-Size="11pt" Width="316px"></asp:Label>
                    </div>
                    <div style="text-align: center;">
                        <asp:Button ID="btn_cancelalert" runat="server" CssClass="myButton" Text="  OK  "
                            Width="74px" /></div>
                </div>
                <div class="footerCategory" align="right">
                </div>
            </asp:Panel>


////////////////Script

<script type="text/javascript">
$('#<%=lbl_messages.ClientID%>').html("To date must be grater than From Date"); 
$find('ModalAlertB').show();
return false;
                    
</script>

Convert and Validate Datetime dd/mm/yyyy to mm/dd/yyyy using javascript

//Script

var d1 = "18-10-2014";
var d2 = "18-9-2014";                  
var split = d1.split('-');
var s2= d2.split('-');
var initial=[split[1], split[0], split[2]].join('/');
var i2=[s2[1], s2[0], s2[2]].join('/');
var da =new Date(initial);
var daq =new Date(i2);
var da1=new Date(da.getFullYear(),da.getMonth(),da.getDate());
var da2=new Date(daq.getFullYear(),daq.getMonth(),daq.getDate());
if(da1>da2)
{
alert(1);
}
if(da1<da2)
{
alert(2);
}

//Result


Friday, 18 July 2014

Set and get textboxs and labels values inside gridview using jquery


Select all labels with id= "lblID" inside gridview

$('#<%=gdRows.ClientID %>').find('span[id$="lblID"]').text('Your text.');

Select particular label control out of all the labels with id= "lblID" inside gridview

var $arrL = $('#<%=gdRows.ClientID %>').find('span[id$="lblID"]');
var $lbl = $arrL[0];
$($lbl).text('Your text...');

Similarly, you can also find textbox. Select all textbox with id= "txtID" inside gridview

$('#<%=gdRows.ClientID %>').find('input:text[id$="txtID"]').val('Your value.');

Select particular textbox control out of all the textboxes with id="txtID" inside gridview

var $arrT = $('#<%=gdRows.ClientID %>').find('input:text[id$="txtID"]');
var $txt = $arrT[0];
$($txt).val('text...');

//HTML
<asp:GridView runat="server" ID="dgv" AutoGenerateColumns="False" ShowFooter="true">
    <Columns>
        <asp:BoundField DataField="id" HeaderText="id" />
        <asp:TemplateField HeaderText="from">

            <ItemTemplate>
               <asp:TextBox ID="txtfromff" runat="server"></asp:TextBox>
            </ItemTemplate>
            <FooterTemplate>
            <asp:TextBox ID="txt_from" class="d_from" runat="server"></asp:TextBox>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="to"> 
            <ItemTemplate>
            <asp:TextBox ID="txttott"  runat="server"></asp:TextBox>
              
            </ItemTemplate>
            <FooterTemplate>            
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </FooterTemplate>
        </asp:TemplateField>
    </Columns>

</asp:GridView>


//Script
<script type="text/javascript">

function SetDissVenderValue() {
                    var ddlvalue = $('#<%=ddl_venderDiss.ClientID%> option:selected').text();
                    var $arrT = $('#<%=DGV_Dissimination.ClientID %>').find('input:text[id$="txt_vender"]');
                    var $txt = $arrT[0];
                    $($txt).val(ddlvalue);
                    $find('showselecven').hide();
                    return false;
                }
 </script>


Search data from sql database All data and with condition using single query


//Sql Query

declare @tt int
set @tt=0
select * from mstCombobox_T where (@tt<>0 and Flag=@tt) or (Flag<>0 and @tt=0)

//Output


declare @tt int
set @tt=12
select * from mstCombobox_T where (@tt<>0 and Flag=@tt) or (Flag<>0 and @tt=0)


//Output


Friday, 11 July 2014

Check uploaded file size in asp.net using javascript


//HTML

<asp:FileUpload ID="upl1" runat="server" onchange="CheckFileSize(this.id);" />

//SCRIPT

<script type="text/ecmascript">
 function CheckFileSize(upid) {
                var maxsize = 5 * 1024//1kb=1*1024
                var aspFileUpload = document.getElementById("" + upid + "");
                var filesze = aspFileUpload.files[0].size;
                if (filesze > maxsize) {
                    alert("Maximum file size is " + maxsize / (1024) + "KB");
                    return false;
                }
}

</script>

Thursday, 10 July 2014

Split string values in sql server and insert into DATABASE

There are tow way to do this-
1- Using CHARINDEX 
2- Using PATINDEX 

1- Using CHARINDEX 
declare @string varchar(500)
SET @string = '1,2,3,4,5,'
declare @pos numeric(20)
declare @piece varchar(50)

SET @pos = charindex(',' , @string)
while @pos <> 0
begin
SET @piece = LEFT(@string, @pos-1)
print @piece
SET @string = stuff(@string, 1, @pos, NULL)
SET @pos = charindex(',' , @string)
end
print @string  --this is required to print last string
Output:
2- Using PATINDEX 
declare @string varchar(500)


1
2
3
4
5


SET @string = 'abc-xyx-pqr-ttt-mmm-'
declare @pos numeric(20)
declare @piece varchar(50)

SET @pos = patindex('%,%' , @string)
while @pos <> 0
begin
SET @piece = LEFT(@string, @pos-1)
print @piece
SET @string = stuff(@string, 1, @pos, NULL)
SET @pos = charindex(',' , @string)
end
print @string  --this is required to print last string
Output:
abc
xyx
pqr
ttt
mmm

 Insert Into datatable-

declare @string varchar(500)
SET @string = 'bb,tt,er,1,2,3,4,5,6,7,8,'
declare @pos int
declare @piece int

SET @pos = charindex(',' , @string)
while @pos <> 0
begin
SET @piece = LEFT(@string, @pos-1)
print @piece
SET @string = stuff(@string, 1, @pos, NULL)
SET @pos = charindex(',' , @string)
insert into test1(code)values(@piece)

end

Output:







Monday, 7 July 2014

Enable disable textbox inside gridview using javascript and jquery


//HTML

<asp:GridView ID="gvM" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:CheckBox runat="server" ID="chkid" onclick="GetCheckStatus()"></asp:CheckBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:TextBox runat="server" ID="txtId"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField AccessibleHeaderText = "Name" DataField="Name" />
<asp:CheckBox runat="server" ID="chkid1" ebnable="false"></asp:CheckBox>
        </Columns>
    </asp:GridView>


//Javascrip

<script language="javascript" type="text/javascript">
function GetCheckStatus() {
 var srcControlId = event.srcElement.id;
 var targetControlId = event.srcElement.id.replace('chkid', 'txtId');
 if (document.getElementById(srcControlId).checked)
      document.getElementById(targetControlId).disabled = false;
 else
      document.getElementById(targetControlId).disabled = true;
}
        </script>

//Jquery

 <script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script>

 $(document).ready(function () {
                        jScript();
                    });

                    function jScript() {
                        $("input[type=checkbox][id*=chkid]").click(function () {
                            if (this.checked) {
                                $(this).closest("tr").find("input[type=checkbox][id*=chkid1]").attr("checked", true);
                            }
                            else {
                                $(this).closest("tr").find("input[type=checkbox][id*=chkid1]").attr("checked", false);
                            }
                        });

                    }

//Result



Wednesday, 2 July 2014

Checkbox oncheckedchanged inside gridview in asp.net using javascript

//JavaScript

 function CheckedChange(objCheckBox) {
            if (confirm('Are you sure , You want to change status?')) {
                __doPostBack("'" + objCheckBox.id + "'", '');
                return true;
            }
            else {
                return false;
            }
        }

//Html
<asp:GridView ID="gv_Knowledge" runat="server">
 <asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign="Center">
                                                <ItemTemplate>
                                                    <asp:CheckBox ID="Chk_ActiveKnow" runat="server" Checked='<%# Eval("Active") %>' oncheckedchanged="Chk_ActiveKnow_CheckedChanged" 
                                                    AutoPostBack="true"
                                                        onclick="javascript:return CheckedChange(this);"/>
                                                </ItemTemplate>
                                                <ItemStyle HorizontalAlign="Center" />

                                            </asp:TemplateField>

<asp:GridView/>

Tuesday, 1 July 2014

select data from .xlsx or .xls using ms sql query


//Open Microsoft provider
sp_configure 'Show Advanced Options', 1;
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
GO

EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 0 
GO 
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 0
GO 

//sheet


  SELECT *
FROM   OPENROWSET('Microsoft.ACE.OLEDB.12.0',
       'Excel 12.0 Xml;HDR=YES;Database=C:\Users\krishna\Desktop\tt.xlsx',
       'SELECT * FROM [Sheet1$]')

//result


Generate Random Numeric in sql server

 DECLARE @intFlag INT
declare @rand numeric(18,0)
Set @intFlag = 1

WHILE (@intFlag <=1000)
BEGIN
select @rand= convert(numeric(12,0),rand() * 89999999) + 10000000SET @intFlag = @intFlag + 1
print @rand
END



Result-


How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...