Tuesday, December 30, 2008

Filtering With Data View In .NET:

Retrieving data from SQL SERVER is a common Task. But retrieving, every time for a single filtering makes a complicate Task. To avoid this we can make use of Data view in asp.net.
Once we retrieve the data into dataset, we can simply make use of that dataset for further filtering process.
Here in this sample example, I have a dsClientAssignment as a dataset which contains whole data with different designations .But iam filtering only manager designation.And I am again binding to dsClientAssignmentFilter dataset for further use.

Test.vb

Dim viewClientAssignment As New DataView
Dim dsClientAssignmentFilter As New DataSet
Dim strFil, sDiv, msPrevDiv As String
viewClientAssignment = dsClientAssignment.Tables(0).DefaultView
strFil = "Designation='manager'"
viewClientAssignment.RowFilter = strFil
viewClientAssignment.RowStateFilter = DataViewRowState.CurrentRows
dsClientAssignmentFilter.Tables(0).Merge(viewClientAssignment.ToTable.DefaultView.Table)

Monday, December 29, 2008

Selecting Second Maximum Record From Table in SQL SERVER.

We know that, how to select a maximum Record from table Using SQL SERVER.
For Example.

select max(stor_id) from sales
Syntax:
select max(Column_name) from Table_name

But, It is little bit complex to find a Second Max Record From Table.
We can Overcome this Problem by using this Simple Query.

select max(stor_id) from sales where stor_id not in (select max(stor_id) from sales)

Syntax:
select max(Column_name) from Table_name where Column_name not in (select max(Column_name) from Table_name)

This is Nested Sub Query.

Monday, December 22, 2008

EO:call back panel can be used instead of Ajax: update panel in .NET

Simply put a Callback Panel inside the form and other controls that you want to AJAX-update inside the Callback Panel; When multiple Callback Panels are grouped together, triggering any one of them triggers them all. Ideal for updating different regions in the same page with one AJAX call;

A sample Example on this Topic.

Test1.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test1.aspx.vb" Inherits="Test1" %>
<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<eo:CallbackPanel ID="cbpTargetTable" runat="server"
ClientSideAfterUpdate ="ShowDialogs" LoadingDialogID="dlgProcessing" Width="100%" AutoDisableContents="true"
Triggers="{ControlID:Dialog1;Parameter:};{ControlID:ddltest1;Parameter:};{ControlID:ddltest2;Parameter:}" >

<center>
<table cellpadding="2" cellspacing="6">
<tr>
<td align="left" ><asp:Label ID="Lbltest1" runat="server" Text="Test1 DDL"></asp:Label></td>
<td align="left" ><asp:DropDownList AutoPostBack="true" ID="ddltest1" Width="135" runat="server">
<asp:ListItem Text="--Select--"></asp:ListItem>
<asp:ListItem Text ="Cars"></asp:ListItem>
<asp:ListItem Text="Bikes"></asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td align="left"><asp:Label ID="Lbltest2" runat="server" Text="Test2 DDL"></asp:Label></td>
<td align="left"><asp:DropDownList AutoPostBack="true" Enabled ="false" Width="135" ID="ddltest2" runat="server"></asp:DropDownList></td>

</tr>
<tr>
<td><a runat="server" href="#" id="HypCustomer" onclick="eo_GetObject('Dialog1').show();" >View EO POPUP DIALOG</a></td>
</tr>

</table>
<eo:dialog HeaderHtml="History" ActivateOnClick="true" BackShadeColor="Blue" ContentHtml="EO Dialog POPUP DEMO" runat="server" Height="400" Width="400" id="Dialog1" ControlSkinID="None"
BorderStyle="Solid" CloseButtonUrl="00070101" BorderWidth="1px"
ShadowColor="LightGray" BorderColor="#335C88" ShadowDepth="3"
MinimizeButtonUrl="00070102"
AllowResize="True"
RestoreButtonUrl="00070103"
ResizeImageUrl="00020014"
AcceptButton="btnOK"
AcceptButtonPostBack="true">
<headerstyleactive csstext="padding-right: 4px; padding-left: 4px; font-size: 11px; background-image: url(00070104); padding-bottom: 3px; padding-top: 3px; font-family: tahoma"></HeaderStyleActive>
<contentstyleactive csstext="border-top: #335c88 1px solid; background-color: #e5f1fd"></contentstyleactive>
<footerstyleactive csstext="border-right: #22456a 1px solid; background-image: url(00070104); padding-right: 4px; border-top: #7d97b6 1px solid; padding-left: 4px; border-left-width: 1px; font-size: 11px; border-left-color: #728eb8; padding-bottom: 4px; color: white; padding-top: 4px; border-bottom: #22456a 1px solid; font-family: verdana"></FooterStyleActive>
<FooterTemplate >
<asp:Button ID="Button1" runat="server" Text="Close" />
</FooterTemplate>
</eo:dialog>
</center>
</eo:CallbackPanel>
<eo:Dialog runat="server" id="dlgProcessing" BackColor="white" BorderWidth="1" BackShadeColor="Blue" ShadowColor="LightGray" BorderColor="#335C88" ShadowDepth="3" >
<ContentTemplate>
<table border="0" width="250">
<tr>
<td align="center">
<img src="<%= ResolveUrl("Images/indicator.gif") %>" />
</td>
</tr>
<tr>
<td align="center"><b>Please wait...</b></td>
</tr>
</table>
</ContentTemplate>
</eo:Dialog>

</form>
</body>
</html>

IN TEST1.VB

Partial Class Test1
Inherits System.Web.UI.Page
Protected Sub ddltest1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddltest1.SelectedIndexChanged
If ddltest1.SelectedItem.Text <> "--Select--" Then
ddltest2.Items.Clear()
ddltest2.Enabled = True
If ddltest1.SelectedItem.Text = "Cars" Then
ddltest2.Items.Insert(0, "BMW")
ddltest2.Items.Insert(1, "Ford")
ddltest2.Items.Insert(2, "Innova")
Else
ddltest2.Items.Insert(0, "CBZ")
ddltest2.Items.Insert(1, "Pulsar")
ddltest2.Items.Insert(2, "Karizna")
End If
Else
ddltest2.Items.Clear()
ddltest2.Enabled = False
End If
End Sub

NOTE:
To raise an event in eo:call back Panel Use the Execute event.
From above Example the event should raise as follows:

'Protected Sub cbpTargetTable_Execute(ByVal sender As Object, ByVal e As EO.Web.CallbackEventArgs) Handles cbpTargetTable.Execute
' If e.TriggerControlID = "ddlTest1" Then
' Your Code
' End If
'End Sub

Monday, November 17, 2008

Passing Dataset or Datatable to WEBSERVICE

1. Open VS2005
2. Add a new Website.
3. Create a New Web Service

IN TestWebService.asmx

"Hello World" is Default Function
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function

Add a Function as shown below
<WebMethod()> _
Public Function PICKLIST(ByVal dsInput As Data.DataSet) As Data.DataSet
'Here dsInput is ur Table…..
'I am Returning the dataset

Return ds
End Function

Making use of this WebService in Our Application

• Open VS2005
• Add a new Website.
• Create a New Web Application
• Open Solution Explorer
• Right Click on Your Website
• Select Add Reference
• Give the Path of Your Webservice
• Add Click On “GO”
• And then Click on Add Reference
• Your Reference is added to AddReferences Folder

IN TestWebApplication.vb

Add make use of that Reference in your Page_Load
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ObjWeb As New localhost.TestWebService
'Binding the Webservice Output to Grid
‘Here ds is ur Input Table and it will return the output

GridView1.DataSource = ObjWeb.PICKLIST(ds)
GridView1.DataBind()
End Sub
Note:Datatable may cause Problems.So Prefer dataset's.
If it is necessary convert datatable to dataset. Like
Dim ds As New Data.DataSet
ds.Tables.Add(dtTable)

Monday, October 20, 2008

Using AJAX Auto complete Extender control in ASP.NET:

We often use Ajax controls in our projects. But simple mistakes make a project difficult.
I came across this problem by searching a lot in different forums and websites.
Now I am explaining full length of code in my blogspot.
AutoComplete is an ASP.NET AJAX extender that can be attached to any TextBox control, and will associate that control with a popup panel to display words that begin with the prefix typed into the textbox

IN ASP.NET

<form id="aspnetForm" name="aspnetForm" runat="server">
<asp:ScriptManager runat="server" />
<div class="demoarea">
<div class="demoheading">AutoComplete Control lab</div>
<p/>
Type something
:
<asp:TextBox runat="server" ID="myTextBox" Width="300" autocomplete="off" />
<AJAX:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="myTextBox" ServicePath="test.asmx" ServiceMethod="GetResults" MinimumPrefixLength="1"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="12" />

IN WEBSERVICE Test.vb

Imports System.Web
Imports System.Web.Services
Imports System.Web.Script.Services
Imports System.Web.Services.Protocols
Imports System.Data.SqlClient
Imports System.Data
Imports System.Collections.Generic

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
Inherits System.Web.Services.WebService

<WebMethod(EnableSession:=True)> _
Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()
Dim ds As New DataSet
Dim pre
Dim i As Integer
ds = Session("dsStyle")
If ds.Tables(0).Rows.Count <> 0 Then
Dim items As New List(Of String)
For i = 0 To ds.Tables(0).Rows.Count - 1
pre = ds.Tables(0).Rows(i).Item("matinfo")
If prefixText.ToLower = pre.Substring(0, prefixText.Length).ToLower Or prefixText.ToUpper = pre.Substring(0, prefixText.Length).ToUpper Then
items.Add(ds.Tables(0).Rows(i).Item("matinfo").ToString())
End If
Next
Return items.ToArray
End If

Here in this webservice,i got a data in dataset from sessions .To activate sessions in Webservice we have to include EnableSession:=True as mentioned above.Please let me know if there are any queries.
Thanks.

Sunday, October 19, 2008

Capturing a Event in .NET

If there are more controls in our application. In some cases,in every postback all events raise at a time.
So,at that time capturing an event is necessary.I have faced this problem,and i came up with this solution.Hope it will help u.
IMP : Call this Function in Page_Init

IN VB.NET

Function Getfieldname(ByVal targPage As Page) As String
vfieldname = ""
If targPage.IsPostBack Then
Dim keyName As String
For Each keyName In targPage.Request.Form
If Not keyName Is Nothing Then
If keyName.Length >= 41 Then
If keyName.Substring(0, 41) = "ctl00$ContentPlaceHolder1$ImgbtnConfigure" Then
vfieldname = "ADD"
rowid = keyName.Substring(41, 1)
End If
End If
End If
Next
End If
End Function

Thursday, October 16, 2008

Creating Dynamic Table in ASP.NET

The central point is, with ASP.NET, you need to forget HTML. Stop thinking of rendering a "table". Instead, use an ASP.NET Server Control. It will render the table.

Now,I am creating a dynamic(run time ) Table with a Textbox and Dropdownlist with 10 rows

And Here is the code

IN ASP.NET


<form id="form1" runat="server">
<div>
<asp:Table ID="table1" runat ="server" >
<asp:TableHeaderRow ID="TableHeaderRow1" CssClass="TableBorderHeadline" runat="server" >
<asp:TableHeaderCell ID="TableHeaderCell1" runat="server" >TextBox </asp:TableHeaderCell>
<asp:TableHeaderCell ID="TableHeaderCell2" runat="server" >Dropdownlist</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</div>
</form>




IN VB.NET

Public tblCol(10) As TableCell
Public tblRow(10) As TableRow
Public txtfirst(10) As TextBox
Public ddlfirst(10) As DropDownList


Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim itemCount As Integer
For itemCount = 1 To 10
tblRow(itemCount) = New TableRow

'----this is for txtfirst textbox---------
tblCol(1) = New TableCell
txtfirst(itemCount) = New TextBox
txtfirst(itemCount).ID = "txtfirst" & itemCount
tblCol(1).Controls.Add(txtfirst(itemCount))
tblRow(itemCount).Cells.Add(tblCol(1))
table1.Rows.Add(tblRow(itemCount))


'------this is for ddlfirst dropdownlist------

tblCol(2) = New TableCell
ddlfirst(itemCount) = New DropDownList
ddlfirst(itemCount).ID = "ddlfirst" & itemCount
ddlfirst(itemCount).Width = "70"
tblCol(2).Controls.Add(ddlfirst(itemCount))
tblRow(itemCount).Cells.Add(tblCol(2))
table1.Rows.Add(tblRow(itemCount))
Next
End Sub