Monday, 29 July 2013

Find controls inside table in asp.net c#

 string allTextBoxValues = "";
        foreach (Control c in tableid.Controls)//table control
        {
            foreach (Control childc in c.Controls)//table row
            {
                foreach (Control dd in childc.Controls)//table cell
                {
                    if (dd is TextBox) //controls
                    {
                        allTextBoxValues += ((TextBox)dd).Text + ",";
                    }
                }
               
            }
        }

Thursday, 25 July 2013

replace special character from string using javascript


<script>
var str1 = "a,d,k";
str1 = str1.replace (/,/g, "");
alert(str1);

</script>

find text and value from checkboxlist using javascript

//script

<script language="javascript">
    function GetSelectedValue() {
        var chkBox = document.getElementById("chkList");
        var checkbox = chkBox.getElementsByTagName("input");
var pp;
var txt='';
        for (var i = 0; i < checkbox.length; i++) {
            if (checkbox[i].checked) {
                var chkBoxText = checkbox[i].parentNode.getElementsByTagName('label');
                if (txt == "") {
txt=chkBoxText[0].innerHTML;
pp=checkbox[i].value;
                }
                else {                
txt=txt+", "+chkBoxText[0].innerHTML;
pp=pp+","+checkbox[i].value;
                }
            }
        }
alert(pp+"       "+txt);
    }
</script>



//html

<div>
        <table id="chkList" onclick="GetSelectedValue();">
<tr>
<td><input id="chkList_0" type="checkbox" name="chkList$0" value="0" /><label for="chkList_0">0 Checkbox in DDL</label></td>
</tr><tr>
<td><input id="chkList_1" type="checkbox" name="chkList$1" value="1" /><label for="chkList_1">1 Checkbox in DDL</label></td>
</tr><tr>
<td><input id="chkList_2" type="checkbox" name="chkList$2" value="2" /><label for="chkList_2">2 Checkbox in DDL</label></td>
</tr><tr>
<td><input id="chkList_3" type="checkbox" name="chkList$3" value="3" /><label for="chkList_3">3 Checkbox in DDL</label></td>
</tr><tr>
<td><input id="chkList_4" type="checkbox" name="chkList$4" value="4" /><label for="chkList_4">4 Checkbox in DDL</label></td>
</tr><tr>
<td><input id="chkList_5" type="checkbox" name="chkList$5" value="5" /><label for="chkList_5">5 Checkbox in DDL</label></td>
</tr><tr>
<td><input id="chkList_6" type="checkbox" name="chkList$6" value="6" /><label for="chkList_6">6 Checkbox in DDL</label></td>
</tr><tr>
<td><input id="chkList_7" type="checkbox" name="chkList$7" value="7" /><label for="chkList_7">7 Checkbox in DDL</label></td>
</tr><tr>
<td><input id="chkList_8" type="checkbox" name="chkList$8" value="8" /><label for="chkList_8">8 Checkbox in DDL</label></td>
</tr><tr>
<td><input id="chkList_9" type="checkbox" name="chkList$9" value="9" /><label for="chkList_9">9 Checkbox in DDL</label></td>
</tr>
</table>
    </div>

Tuesday, 23 July 2013

enable javascript in all browser information

Put this under head tag- <head>

<noscript>  <h3 style="color#FF3300;">
Javascript is not currently enabled in your browser.<br /> You must <ahref="http://support.google.com/bin/answer.py?hl=en&answer=23852" target="_blank">enable Javascript </a> to run this web page correctly. 
</h3></noscript>

listbox in c# when bind with datatable

string pp=string.empty;

foreach (var list in cluster_list.SelectedItems)
{
DataRowView drv = (DataRowView)list;
string valueOfItem = drv["ColumnsName"].ToString();
pp = pp + valueOfItem + " ";

Monday, 22 July 2013

filter only text and space in textbox using ajax

<asp:TextBox ID="txt_fatherHasbandName" runat="server" Width="153px"></asp:TextBox>
                                                    <asp:FilteredTextBoxExtender ID="Filter_fathername" runat="server" TargetControlID="txt_fatherHasbandName" ValidChars="abcdef ">
                </asp:FilteredTextBoxExtender>

Thursday, 11 July 2013

only alphabet allowed in textbox on keypress

private void txt_producerName_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !(char.IsLetter(e.KeyChar) || e.KeyChar == (char)Keys.Back);
        }

only numeric in textbox in c#

private void txt_producerName_KeyPress(object sender, KeyPressEventArgs e)
        {
           try
            {
                if (Convert.ToInt16(e.KeyChar) == 8)
                    backspaceflag = true;
                else
                    backspaceflag = false;
                if (char.IsNumber(e.KeyChar) || Convert.ToInt16(e.KeyChar) == 8)
                {
                    e.Handled = false;
                }
                else
                {
                    e.Handled = true;
                }

            }
            catch (Exception ex)
            {
            }
        }

Thursday, 4 July 2013

select all columns from all tables

DECLARE @SQL AS VarChar(MAX)
SET @SQL = ''
SELECT @SQL = @SQL + 'SELECT * FROM ' + TABLE_SCHEMA + '.' + TABLE_NAME + CHAR(13)
FROM INFORMATION_SCHEMA.TABLES
EXEC (@SQL)


OR

sp_msforeachtable 'select  * from ?'

all tables from database with rows count

SELECT sc.name +'.'+ ta.name TableName,SUM(pa.rows) RowCnt
 FROM sys.tables ta INNER JOIN sys.partitions pa
 ON pa.OBJECT_ID = ta.OBJECT_ID
 INNER JOIN sys.schemas sc ON ta.schema_id = sc.schema_id
 WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)
 GROUP BY sc.name,ta.name
 ORDER BY SUM(pa.rows) DESC

switch case

public string setpagevalue(string pagename)
    {
        string valdata = pagename;
        switch(valdata){
            case "ASP.formshome_aspx": return "Home Page"; break;
            case "ASP.admin_aspx": return "Administration Page";break;
            case "ASP.import_data_aspx": return "Import Data Page"; break;
            case "ASP.report_aspx": return "Report Page"; break;
            case "ASP.vfamemberprofile_aspx": return "VFA Member Profile"; break;
         
             //default
            default: return string.Empty;
                break;      
        }
    } 

Get child page full name Which is run currently

 string PageName = this.ContentPlaceHolder1.Page.GetType().FullName;

Create NONCLUSTERED index in sql server

CREATE UNIQUE NONCLUSTERED INDEX [IX_TableName_FieldName]
ON [dbo].[TableName]
(
[FieldName] ASC
) WITH (IGNORE_DUP_KEY = ON) ON [PRIMARY]

Get all table name from Particular database

SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'

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...