Private Function SelectedValues() As String
Dim strValues As String = ""
For i As Integer = 0 To GridView.Rows.Count - 1
Dim chkSelect As CheckBox
chkSelect = CType(gvClientContact.Rows(i).FindControl("chkSelect"), CheckBox)
If Not chkSelect Is Nothing Then
If chkSelect.Checked Then
strValues &= CStr(GridView.DataKeys(i).Values(0)) & ","
End If
End If10/09/2010
Next
Return strValues.Trim(CChar(","))
End Function
Friday, October 28, 2011
Get selected values of checkbox from GridView in ASP.NET
Wednesday, October 19, 2011
Circular matrix in vb.net
Dim c As Integer = 1
Dim i, j, k, n, x As Integer
Dim m As Integer = 0
n = 5
x = n
Dim a(n, n) As Integer
While n >= 1
For k = 0 To n - 1
a(m, k + m) = c
c = c + 1
Next
For k = 1 To n - 1
a(k + m, n - 1 + m) = c
c = c + 1
Next
For k = n - 2 To 0 Step -1
a(n - 1 + m, k + m) = c
c = c + 1
Next
For k = n - 2 To 1 Step -1
a(k + m, m) = c
c = c + 1
Next
n = n - 2
m = m + 1
End While
Dim strB As New StringBuilder
strB.Append("<table border='1'>")
For i = 0 To x - 1
strB.Append("<tr>")
For j = 0 To x - 1
strB.Append("<td>")
strB.Append(a(i, j))
strB.Append("</td>")
Next
strB.Append("</tr>")
Next
strB.Append("</table>")
Response.Write(strB)
Friday, October 14, 2011
Get selected checkbox value of ASP.NET GRID VIEW using JavaScript
<script language="javascript" type="text/javascript">
function GetSelected(objchk, HId) {
var hdnIds = document.getElementById("<%= hdnIds.ClientId %>");
if (hdnIds.value.length == 0) {
hdnIds.value = ",";
}
if (objchk.checked == true) {
hdnIds.value = hdnIds.value + HId + ",";
}
else {
hdnIds.value = hdnIds.value.replace("," + HId + ",", ",")
}
}
</script>
'Bind this function like On GridView's RowDataBound Event.
Private Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
Dim chkSelect As CheckBox = CType(e.Row.FindControl("chkSelect"), CheckBox)
If Not chkSelect Is Nothing Then
chkSelect.Attributes.Add("onclick", "GetSelected(this,'" & DataBinder.Eval(e.Row.DataItem, "HId").ToString() & "');")
End If
End Sub
'Now you have comma seperated values of HIds in hdnIds hidden field which you can use accordingly
Labels:
Asp.Net,
checkbox,
grid view,
Javascript,
selected value
Wednesday, October 12, 2011
Find post back control with JavaScript
<script language="javascript" type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
var PostBackCtrl;
function BeginRequestHandler(sender, e) {
PostBackCtrl = e.get_postBackElement();
}
function EndRequestHandler(sender, e) {
if (PostBackCtrl.id.toLowerCase().indexOf("yourcontrolname") > 0 ) {
//This is your control which made post back
//write your code here
}
}
</script>
Monday, October 10, 2011
SQL Code to generate properties for vb.net
/*
SQL Code to generate properties for vb.net
*/
Declare @TableName varchar(100)
Set @TableName ='TableName'
Declare @Column1 varchar(300),
@Datatype varchar(50),
@ActColumn1 varchar(300),
@FieldType varchar(50)
print '============================================================================================='
print '#Region "Fields" '
DECLARE get_Data CURSOR
FOR SELECT COLUMN_NAME ,DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
ORDER BY ORDINAL_POSITION
OPEN get_Data
FETCH NEXT FROM get_Data into @Column1,@Datatype
WHILE @@FETCH_STATUS = 0
BEGIN
set @ActColumn1 = @Column1
if @Datatype = 'int'
Set @FieldType = 'Integer'
else if @Datatype = 'tinyint'
Set @FieldType = 'Int16'
else if @Datatype = 'float'
Set @FieldType = 'Double'
else if @Datatype = 'varchar' or @Datatype = 'text'
Set @FieldType = 'String'
else
Set @FieldType = @Datatype
print 'Private _' + @Column1 + ' as ' + @FieldType
FETCH NEXT FROM get_Data into @Column1,@Datatype
End
CLOSE get_Data
DEALLOCATE get_Data
print ' #End region'
print '============================================================================================='
print '============================================================================================='
print '#Region "Properties" '
DECLARE get_Data CURSOR FOR
SELECT COLUMN_NAME ,DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
ORDER BY ORDINAL_POSITION
OPEN get_Data
FETCH NEXT FROM get_Data into @Column1,@Datatype
WHILE @@FETCH_STATUS = 0
BEGIN
set @ActColumn1 = @Column1
if @Datatype = 'int'
Set @FieldType = 'Integer'
else if @Datatype = 'tinyint'
Set @FieldType = 'Int16'
else if @Datatype = 'float'
Set @FieldType = 'Double'
else if @Datatype = 'varchar' or @Datatype = 'text'
Set @FieldType = 'String'
else
Set @FieldType = @Datatype
print 'public property ' + @Column1 + '() as ' + @FieldType
print 'Get'
print 'return _' + @ActColumn1
print ' End Get'
print 'Set(ByVal Value as '+ @FieldType +')'
print '_' + @ActColumn1 + ' = value'
print ' End Set'
print 'End Property'
FETCH NEXT FROM get_Data into @Column1,@Datatype
End
CLOSE get_Data
DEALLOCATE get_Data
print ' #End region'
print '============================================================================================='
print '============================================================================================='
print '#Region "Method" '
print ' Public Function InsertUpdate() As Integer
Dim db As Database = Nothing
Dim dbCommand As DbCommand = Nothing
Try
db = DatabaseFactory.CreateDatabase()
dbCommand = db.GetStoredProcCommand("'+Replace(@TableName,'_','')+'_InsertUpdate")'
DECLARE get_Data CURSOR FOR
SELECT COLUMN_NAME ,DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
ORDER BY ORDINAL_POSITION
OPEN get_Data
FETCH NEXT FROM get_Data into @Column1,@Datatype
WHILE @@FETCH_STATUS = 0
BEGIN
set @ActColumn1 = @Column1
if @Datatype = 'int'
Set @FieldType = 'Int32'
else if @Datatype = 'tinyint'
Set @FieldType = 'Int16'
else if @Datatype = 'float'
Set @FieldType = 'Double'
else if @Datatype = 'varchar' or @Datatype = 'text'
Set @FieldType = 'String'
else
Set @FieldType = @Datatype
print ' db.AddInParameter(dbCommand, "@'+@Column1+'", DbType.'+@FieldType+', _'+@Column1+')'
FETCH NEXT FROM get_Data into @Column1,@Datatype
End
CLOSE get_Data
DEALLOCATE get_Data
print ''
print ' Dim returnValue As Integer = Convert.ToInt32(db.ExecuteScalar(dbCommand))
Return returnValue
Finally
BObase.DisposeOf(dbCommand)
BObase.DisposeOf(db)
End Try
End Function'
print 'Public Function View() As Boolean'
print ' Dim dt As DataTable = Me.SelectById()'
print ' If Not BObase.IsNothingOrEmpty(dt) Then'
print ' Dim dr As DataRow = dt.Rows(0)'
print ' BObase.SetDefaultValuesForDBNull(dr)'
print ' With Me'
DECLARE get_Data CURSOR
FOR SELECT COLUMN_NAME ,DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
ORDER BY ORDINAL_POSITION
OPEN get_Data
FETCH NEXT FROM get_Data into @Column1,@Datatype
WHILE @@FETCH_STATUS = 0
BEGIN
print ' ._' + @Column1 + ' = dr("' + @Column1 + '")'
FETCH NEXT FROM get_Data into @Column1,@Datatype
End
CLOSE get_Data
DEALLOCATE get_Data
print ' End With'
print ' Return True'
print ' Else'
print ' Return False'
print ' End If'
print 'End Function'
print ' #End region'
print '============================================================================================='
print ' With objProperties'
DECLARE get_Data CURSOR
FOR SELECT COLUMN_NAME ,DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
ORDER BY ORDINAL_POSITION
OPEN get_Data
FETCH NEXT FROM get_Data into @Column1,@Datatype
WHILE @@FETCH_STATUS = 0
BEGIN
set @ActColumn1 = @Column1
If @Datatype='int'
begin
set @Datatype='Integer'
set @ActColumn1= substring(@Column1,0,len(@Column1)+1)
set @Column1='lst' + substring(@Column1,0,len(@Column1)+1) + '.SelectedValue'
end
else if @Datatype='nvarchar'
begin
set @Datatype='String'
set @ActColumn1= substring(@Column1,0,len(@Column1)+1)
set @Column1='txt' + substring(@Column1,0,len(@Column1)+1) +'.text'
end
else if @Datatype='datetime'
begin
set @Datatype='String'
set @ActColumn1= substring(@Column1,0,len(@Column1)+1)
set @Column1='txt' + substring(@Column1,0,len(@Column1)+1) +'.text'
end
else if @Datatype='bit'
begin
set @Datatype='Boolean'
set @ActColumn1= substring(@Column1,0,len(@Column1)+1)
set @Column1='chk' + substring(@Column1,0,len(@Column1)+1) + '.checked'
end
else if @Datatype='decimal'
begin
set @Datatype='Double'
set @ActColumn1=substring(@Column1,0,len(@Column1)+1)
set @Column1='txt' +substring(@Column1,0,len(@Column1)+1) +'.text'
end
else if @Datatype='float'
begin
set @Datatype='Double'
set @ActColumn1=substring(@Column1,0,len(@Column1)+1)
set @Column1='txt' +substring(@Column1,0,len(@Column1)+1) +'.text'
end
print ' ' + @Column1 + ' = .' + @ActColumn1
FETCH NEXT FROM get_Data into @Column1,@Datatype
End
CLOSE get_Data
DEALLOCATE get_Data
print ' End With'
print '============================================================================================='
print ' With objProperties'
DECLARE get_Data CURSOR
FOR SELECT COLUMN_NAME ,DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
ORDER BY ORDINAL_POSITION
OPEN get_Data
FETCH NEXT FROM get_Data into @Column1,@Datatype
WHILE @@FETCH_STATUS = 0
BEGIN
set @ActColumn1 = @Column1
If @Datatype='int'
begin
set @Datatype='Integer'
set @ActColumn1= substring(@Column1,0,len(@Column1)+1)
set @Column1='lst' + substring(@Column1,0,len(@Column1)+1) + '.SelectedValue'
end
else if @Datatype='nvarchar'
begin
set @Datatype='String'
set @ActColumn1= substring(@Column1,0,len(@Column1)+1)
set @Column1='txt' + substring(@Column1,0,len(@Column1)+1) +'.text'
end
else if @Datatype='datetime'
begin
set @Datatype='String'
set @ActColumn1= substring(@Column1,0,len(@Column1)+1)
set @Column1='txt' + substring(@Column1,0,len(@Column1)+1) +'.text'
end
else if @Datatype='bit'
begin
set @Datatype='Boolean'
set @ActColumn1= substring(@Column1,0,len(@Column1)+1)
set @Column1='chk' + substring(@Column1,0,len(@Column1)+1) + '.checked'
end
else if @Datatype='decimal'
begin
set @Datatype='Double'
set @ActColumn1=substring(@Column1,0,len(@Column1)+1)
set @Column1='txt' +substring(@Column1,0,len(@Column1)+1) +'.text'
end
else if @Datatype='float'
begin
set @Datatype='Double'
set @ActColumn1=substring(@Column1,0,len(@Column1)+1)
set @Column1='txt' +substring(@Column1,0,len(@Column1)+1) +'.text'
end
print ' .' + @ActColumn1 + ' = ' + @Column1
FETCH NEXT FROM get_Data into @Column1,@Datatype
End
CLOSE get_Data
DEALLOCATE get_Data
print ' End With'
print '============================================================================================='
print '============================================================================================='
print '#Region "Fields" '
DECLARE @strOutput varchar(Max)
SET @strOutput = 'public sub New ('
DECLARE get_Data CURSOR
FOR SELECT COLUMN_NAME ,DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
ORDER BY ORDINAL_POSITION
OPEN get_Data
FETCH NEXT FROM get_Data into @Column1,@Datatype
WHILE @@FETCH_STATUS = 0
BEGIN
set @ActColumn1 = @Column1
if @Datatype = 'int'
Set @FieldType = 'Integer'
else if @Datatype = 'tinyint'
Set @FieldType = 'Int16'
else if @Datatype = 'float'
Set @FieldType = 'Double'
else if @Datatype = 'varchar' or @Datatype = 'text'
Set @FieldType = 'String'
else
Set @FieldType = @Datatype
SET @strOutput = @strOutput + @Column1 + ' as ' + @FieldType + ', '
FETCH NEXT FROM get_Data into @Column1,@Datatype
End
CLOSE get_Data
DEALLOCATE get_Data
PRINT @strOutput
print ' #End region'
print '============================================================================================='
print '============================================================================================='
print '#Region "Fields" '
DECLARE get_Data CURSOR
FOR SELECT COLUMN_NAME ,DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
ORDER BY ORDINAL_POSITION
OPEN get_Data
FETCH NEXT FROM get_Data into @Column1,@Datatype
WHILE @@FETCH_STATUS = 0
BEGIN
set @ActColumn1 = @Column1
if @Datatype = 'int'
Set @FieldType = 'Integer'
else if @Datatype = 'tinyint'
Set @FieldType = 'Int16'
else if @Datatype = 'float'
Set @FieldType = 'Double'
else if @Datatype = 'varchar' or @Datatype = 'text'
Set @FieldType = 'String'
else
Set @FieldType = @Datatype
PRINT 'Me.'+ @Column1 + ' = ' + @Column1
FETCH NEXT FROM get_Data into @Column1,@Datatype
End
CLOSE get_Data
DEALLOCATE get_Data
print ' #End region'
print '============================================================================================='
Tuesday, October 4, 2011
Find Modified Procedures,Functions,Views In SQL Server
/*
Below code is for SQL 2008
*/
SELECT 'EXEC sp_HelpText '+name, create_date, modify_date,type
FROM sys.objects
WHERE type in ('P','FN','V','TF')
AND DATEDIFF(D,modify_date, GETDATE()) < 10 --How old the object can be ?
ORDER BY modify_date
Subscribe to:
Posts (Atom)