Oct 29, 2011
Sql Function for padding text to field output
create function ULPAD(@vInput varchar(max), @iLenght smallint,@cPadChar char(1))
returns varchar(max)
as
begin
if @vInput is not null
begin
if LEN(@vInput) <= @iLenght
begin
set @vInput = RIGHT (REPLICATE(@cPadChar, @iLenght)+ CAST (@vInput AS varchar), @iLenght)
end
end
return @vInput
end
Ex:
SELECT @NewEmpNo =dbo.ULPAD((Select com_empsrno +1 from Mcompany where com_code=@Emp_Org_srno) , 5,'0')
Oct 20, 2011
Add Dynamicaly Row in Grid view
'Designer page------------------------------------------------------------
<asp:GridView id="GridQuote" runat="server" DataKeyNames="Quote_srno" ShowHeader="False" GridLines="None" AutoGenerateColumns="False" CellPadding="0" __designer:wfdid="w31"><Columns>
<asp:TemplateField HeaderText="quotes"><ItemTemplate>
<TABLE style="WIDTH: 428px"><TBODY><TR><TD vAlign=top align=right><asp:Label id="Label1" runat="server" Text="Quote :" __designer:wfdid="w38"></asp:Label></TD><TD><uc1:cgTextbox id="txtQuote" runat="server" Height="150" MaxLength="1000" Width="325" TextMode="MultiLine" Text='<%# Eval("Quote") %>' Required="true" __designer:wfdid="w39"></uc1:cgTextbox></TD><TD vAlign=top> <asp:ImageButton id="btnRemQuote" onclick="btnRemQuote_Click" runat="server" ImageUrl="~/App_Themes/images/btnRemove.jpg" CausesValidation="False" __designer:wfdid="w40">
</asp:ImageButton> </TD></TR><TR><TD align=right><asp:Label id="Label2" runat="server" Text="Quote By :" Width="65px" __designer:wfdid="w41"></asp:Label></TD><TD><asp:TextBox id="txtQuoteBy" runat="server" Text='<%# Eval("QuoteBy") %>' MaxLength="50" Width="98%" __designer:wfdid="w42"></asp:TextBox></TD><TD></TD></TR><TR><TD align=right><asp:Label id="Label3" runat="server" Text="Posted By :" Width="71px" __designer:wfdid="w43"></asp:Label></TD><TD><uc2:cgSearchEmp id="CgSearchEmp1" runat="server" UserId='<%#Eval("PostUserId") %>' EmpName='<%# Eval("PostUserNm") %>' EmpNo='<%# Eval("PostEmpNo") %>' __designer:wfdid="w44"></uc2:cgSearchEmp> </TD><TD align=right> <asp:ImageButton id="btnAddMoreQuote" onclick="btnAddMoreQuote_Click" runat="server" ImageUrl="~/App_Themes/images/btnAdd.jpg" Visible="False" CausesValidation="False" __designer:wfdid="w45"></asp:ImageButton> </TD></TR></TBODY></TABLE>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="WhiteSmoke"></AlternatingRowStyle>
</asp:GridView>
'Code Behind..........................................
'On Load page--------------------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
If IsNothing(ViewState("Quote")) Then
MakeTableQuote()
btnAddMoreQuote_Click(sender, TryCast(e, System.Web.UI.ImageClickEventArgs))
End If
End If
End Sub
Protected Sub MakeTableQuote()
Dim dt As New DataTable
Dim dc As DataColumn
dc = New DataColumn("Quote_srno", System.Type.GetType("System.Int32"))
dt.Columns.Add(dc)
dc = New DataColumn("Quote", System.Type.GetType("System.String"))
dt.Columns.Add(dc)
dc = New DataColumn("QuoteBy", System.Type.GetType("System.String"))
dt.Columns.Add(dc)
dc = New DataColumn("PostUserId", System.Type.GetType("System.String"))
dt.Columns.Add(dc)
dc = New DataColumn("PostUserNm", System.Type.GetType("System.String"))
dt.Columns.Add(dc)
dc = New DataColumn("PostEmpNo", System.Type.GetType("System.String"))
dt.Columns.Add(dc)
ViewState("Quote") = dt
End Sub
Protected Sub btnAddMoreQuote_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Dim dt As DataTable = ViewState("Quote")
Dim dr As DataRow
For i As Integer = 0 To GridQuote.Rows.Count - 1
dt.Rows(i).Item(1) = DirectCast(GridQuote.Rows(i).FindControl("txtQuote"), UserControl.TextBox).Text
dt.Rows(i).Item(2) = DirectCast(GridQuote.Rows(i).FindControl("txtQuoteBy"), TextBox).Text
dt.Rows(i).Item(3) = DirectCast(GridQuote.Rows(i).FindControl("CgSearchEmp1"), UserControl.cgSearchEmp).UserId
dt.Rows(i).Item(4) = DirectCast(GridQuote.Rows(i).FindControl("CgSearchEmp1"), UserControl.cgSearchEmp).EmpName
dt.Rows(i).Item(5) = DirectCast(GridQuote.Rows(i).FindControl("CgSearchEmp1"), UserControl.cgSearchEmp).EmpNo
Next
dr = dt.NewRow
dr.Item(0) = 0
dr.Item(1) = ""
dt.Rows.Add(dr)
ViewState("Quote") = dt
bindGridQuote()
End Sub
Protected Sub bindGridQuote()
Dim dt As DataTable = ViewState("Quote")
GridQuote.DataSource = dt
GridQuote.DataBind()
If HiddenFieldMode.Value = "New" Or HiddenFieldMode.Value = "" Then
GridQuote.Rows(GridQuote.Rows.Count - 1).FindControl("btnAddMoreQuote").Visible = True
GridQuote.Rows(GridQuote.Rows.Count - 1).FindControl("btnRemQuote").Visible = False
Else
GridQuote.Rows(GridQuote.Rows.Count - 1).FindControl("btnAddMoreQuote").Visible = False
GridQuote.Rows(GridQuote.Rows.Count - 1).FindControl("btnRemQuote").Visible = False
End If
'For i As Integer = 0 To GridQuote.Rows.Count - 2
' GridQuote.Rows(i).FindControl("btnAddMoreQuote").Visible = False
'Next
End Sub
Protected Sub btnRemQuote_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Dim row As GridViewRow = TryCast(DirectCast(sender, ImageButton).Parent.Parent, GridViewRow)
'lblMsg.Text = row.RowIndex
Dim dt As DataTable = ViewState("Quote")
Dim dr As DataRow
For i As Integer = 0 To GridQuote.Rows.Count - 1
dt.Rows(i).Item(1) = DirectCast(GridQuote.Rows(i).FindControl("txtQuote"), UserControl.TextBox).Text
dt.Rows(i).Item(2) = DirectCast(GridQuote.Rows(i).FindControl("txtQuoteBy"), TextBox).Text
dt.Rows(i).Item(3) = DirectCast(GridQuote.Rows(i).FindControl("CgSearchEmp1"), UserControl.cgSearchEmp).UserId
dt.Rows(i).Item(4) = DirectCast(GridQuote.Rows(i).FindControl("CgSearchEmp1"), UserControl.cgSearchEmp).EmpName
dt.Rows(i).Item(5) = DirectCast(GridQuote.Rows(i).FindControl("CgSearchEmp1"), UserControl.cgSearchEmp).EmpNo
Next
dt.Rows(row.RowIndex).Delete()
ViewState("Quote") = dt
bindGridQuote()
End Sub
Oct 6, 2011
Split function for Sql Server
CREATE FUNCTION dbo.Split
(
@RowData nvarchar(2000),
@SplitOn nvarchar(5)
)
RETURNS @RtnValue table
(
Id int identity(1,1),
Data nvarchar(100)
)
AS
BEGIN
Declare @Cnt int
Set @Cnt = 1
While (Charindex(@SplitOn,@RowData)>0)
Begin
Insert Into @RtnValue (data)
Select
Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))
Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))
Set @Cnt = @Cnt + 1
End
Insert Into @RtnValue (data)
Select Data = ltrim(rtrim(@RowData))
Return
END
(
@RowData nvarchar(2000),
@SplitOn nvarchar(5)
)
RETURNS @RtnValue table
(
Id int identity(1,1),
Data nvarchar(100)
)
AS
BEGIN
Declare @Cnt int
Set @Cnt = 1
While (Charindex(@SplitOn,@RowData)>0)
Begin
Insert Into @RtnValue (data)
Select
Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))
Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))
Set @Cnt = @Cnt + 1
End
Insert Into @RtnValue (data)
Select Data = ltrim(rtrim(@RowData))
Return
END
Sep 28, 2011
How to Get and change style of all dropdown in Jquery
<script type="text/javascript">
$("select").focusin(function() {
jQuery(this).closest("table").css("height","+35");
});
$("select").focusout(function() {
jQuery(this).closest("table").css("height","auto");
});
</script>
$("select").focusin(function() {
jQuery(this).closest("table").css("height","+35");
});
$("select").focusout(function() {
jQuery(this).closest("table").css("height","auto");
});
</script>
Sep 25, 2011
How to add hyperlink in Grid View with DataBinder.Eval()
<asp:datagrid id="Datagrid3" runat="server" AutoGenerateColumns="False" BorderColor="black"
HeaderStyle-CssClass="tableHeader" ItemStyle-CssClass= "tableItem">
<Columns>
<asp:TemplateColumn HeaderText="Order">
<ItemTemplate>
<Columns>
<asp:TemplateColumn HeaderText="Order">
<ItemTemplate>
<asp:Hyperlink runat= "server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductName").tostring%>'
NavigateUrl='<%# "page.aspx?Name=" & DataBinder.Eval (Container.DataItem,"ProductName").tostring & _
"&ProductID=" & DataBinder.Eval(Container.DataItem,"ProductID").tostring %>' ID="ProductName"/>
</ItemTemplate>
</asp:TemplateColumn>
"&ProductID=" & DataBinder.Eval(Container.DataItem,"ProductID").tostring %>' ID="ProductName"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
</asp:datagrid>
Sep 23, 2011
Sep 20, 2011
Up and Down List Box Item Java Script In ASP.NET
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<input type="button" value="Up"onclick="moveUp(this.form['_lb2']);" />
<asp:ListBox ID="_lb2" name="_lb2" runat="server" Height="100px" Width="170px">
<asp:ListItem>Data1</asp:ListItem>
<asp:ListItem>Data2</asp:ListItem>
<asp:ListItem>Data3</asp:ListItem>
<asp:ListItem>Data4</asp:ListItem>
</asp:ListBox>
<input type="button" value="Down"onclick="moveDown(this.form['_lb2']);" />
<div>
<br />
</div>
</form>
</body>
<script type="text/javascript">
function moveUp(sel)
{
var idx = sel.selectedIndex;
var opt;
// Only move up if not first
if (idx > 0)
{
opt = sel.options[idx];
sel.insertBefore(opt, sel.options[--idx]);
}
}
function moveDown(sel)
{
var idx = sel.selectedIndex;
var opt;
// Only move up if not first
if (idx < sel.length-1)
{
opt = sel.options[idx];
sel.insertBefore(sel.options[++idx],opt);
}
}
</script>
</html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<input type="button" value="Up"onclick="moveUp(this.form['_lb2']);" />
<asp:ListBox ID="_lb2" name="_lb2" runat="server" Height="100px" Width="170px">
<asp:ListItem>Data1</asp:ListItem>
<asp:ListItem>Data2</asp:ListItem>
<asp:ListItem>Data3</asp:ListItem>
<asp:ListItem>Data4</asp:ListItem>
</asp:ListBox>
<input type="button" value="Down"onclick="moveDown(this.form['_lb2']);" />
<div>
<br />
</div>
</form>
</body>
<script type="text/javascript">
function moveUp(sel)
{
var idx = sel.selectedIndex;
var opt;
// Only move up if not first
if (idx > 0)
{
opt = sel.options[idx];
sel.insertBefore(opt, sel.options[--idx]);
}
}
function moveDown(sel)
{
var idx = sel.selectedIndex;
var opt;
// Only move up if not first
if (idx < sel.length-1)
{
opt = sel.options[idx];
sel.insertBefore(sel.options[++idx],opt);
}
}
</script>
</html>
Subscribe to:
Posts (Atom)
-
Bootstrap css front-end framework. jQuery fast, small, and feature-rich JavaScript library. DataTables advanced interaction contro...
-
click on below link to send sms http://www.eggheadcafe.com/community/asp-net/17/10281633/code-to-send-sms-using-webservice-like-way2sms.as...
-
// use the following event in Your script tag function pageLoad(sender, args) { if (args.get_isPartialLoad()) { //alert(...
What is the use of n-tier architecture and 3-tier architecture?
how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture. Some people called it ...
