Archive

Archive for March, 2010

Listbox select all using checkbox through Javascript

March 29, 2010 3 comments

In this article, we gonna implement selection of all items in listbox using checkbox through javascript.

<script language=”javascript” type=”text/javascript”>

function SelectAllCountry(chkObj) {
var multi = document.getElementById(‘lstcountry’);
if (chkObj.checked)
for (i = 0; i < multi.options.length; i++)
multi.options[i].selected = true;
else
for (i = 0; i < multi.options.length; i++)
multi.options[i].selected = false;
}

</script>

<asp:CheckBox ID=”chkcountry” OnClick=”SelectAllCountry(this);”
runat=”server” Text=”Select All” />

<asp:ListBox ID=”lstcountry” runat=”server” Rows=”10″ SelectionMode=”Multiple”>

<asp:ListItem Text=”Australia” Value=”Australia”></asp:ListItem>

<asp:ListItem Text=”Germany” Value=”Germany”></asp:ListItem>

<asp:ListItem Text=”Holland” Value=”Holland”></asp:ListItem>

<asp:ListItem Text=”India” Value=”India”></asp:ListItem>

<asp:ListItem Text=”Japan” Value=”Japan”></asp:ListItem>

</asp:ListBox>

Using Asp.net Ajax Update Progress

March 22, 2010 1 comment

Here in this article, we will learn how to use updateprogress control that comes asp.net ajax toolkit.

<asp:ScriptManager ID=”scriptManager” runat=”server” />

<asp:UpdatePanel ID=”UdpLogin” runat=”server”>
<ContentTemplate>

<div>

Content comes here…

</div>
</ContentTemplate>
</asp:UpdatePanel>

<asp:Panel ID=”UpdateProgress” runat=”server” CssClass=”ProgressContent” Width=”100%”
Height=”100%”>
<asp:UpdateProgress ID=”UpdateProg” runat=”server” DisplayAfter=”1″ AssociatedUpdatePanelID=”UdpLogin”>
<ProgressTemplate>
<asp:Panel ID=”UpdatePro” runat=”server” CssClass=”Trans” Width=”100%” Height=”100%”>
<table width=”100%” height=”100%”>
<tr>
<td align=”center” valign=”middle” width=”100%” height=”100%”>
<asp:Image ID=”imgProg” runat=”server” ImageUrl=”~/img/loading.gif” AlternateText=”Updating ……”
ImageAlign=”Middle” />
</td>
</tr>
</table>
</asp:Panel>
</ProgressTemplate>
</asp:UpdateProgress>
</asp:Panel>

Css Styles to include here are as follows:

/* StyleSheet for Update Progress */
.ProgressContent
{
font-family: verdana;
font-size: 11px;
color: #000000;
font-weight: normal;
text-decoration: none;
}

.Trans
{
background-color: White;
filter: alpha(opacity=70);
opacity: 0.7;
position: absolute;
left: 0px;
top: 0px;
}
.Progress
{
font-family: verdana;
font-size: x-small;
color: Green;
font-weight: bold;
text-decoration: none;
height: auto;
}

Please visit my previous article for downloading loading images:

https://pankajlalwani.wordpress.com/2009/05/30/download-ajax-loading-image/

Backup And Restore MySql Database Using MySql Administrator

March 16, 2010 2 comments

Here in this article we will learn how to take backup and restore database in mysql using MySql Administrator Utility.

Steps:

1) Open  MySql Administrator

2) Select Backup in the Left hand side menu

3) Click on “New Project” Button shown at the bottom in the right hand side

4) select your database from the list shown and click “>” arrow button

5) Click on “Execute Backup Now

and save as file dialog will open and save the file accordingly.

To Restore the database, follow the following steps

1) Open MySql Administrator

2) Click on “Restore

3) Click on “Open Backup File

4) Browse file and specify Target Schema click on new schema or specify existing database

5) Click on “Start Restore

Another way of Restoring Db is, follow the below steps:

1) Open MySql Query Browser

2) Click on File menu -> open script – > browse to the backup file

3) Click on Execute

Read/Write Section from/into Web.config in Asp.net

Many times, we need to read sections from web.config or write into web.config.

I have a requirement where i need to write an section in web.config that points to another config file.

Below is the code where “abc” is the section

Configuration objConfig = WebConfigurationManager.OpenWebConfiguration(“~”);
ConfigurationSection section = objConfig.Sections[“abc”];
string str = “abcdef”;
section.SectionInformation.SetRawXml(str);
objConfig.Save();

The above code will read “abc” section and write the content in str.

For Reading Appsettings from web.config, below is the code

Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); AppSettingsSection appSettings = (AppSettingsSection) config.GetSection(appSettings);

string[] appKeys = appSettings.Settings.AllKeys;

for (int i = 0; i < appSettings.Settings.Count; i++)

{

Response.Write(appSettings.Settings[appKeys[i]].Value);

Response.Write(“<BR>”);

}

Insert comma-delimited string value to table column in Sql

March 3, 2010 1 comment

I have string like ‘1,22,3,49,6,7,8’

I want to insert each comma separated value in a table column…my output look like this:

COLUMN
1
22
3
49
6
7
8

Here is the solution:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
— =============================================
— Author:        <Author,,Name>
— Create date: <Create Date,,>
— Description:    <Description,,>

— =============================================
create PROCEDURE [dbo].[sp_InsertCommaSeparatedValues]

AS
BEGIN

DECLARE @FormId VARCHAR(5000)
DECLARE @FormRead varchar(5000)
DECLARE @FormWrite varchar(5000)

SET @FormId = ‘1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,’
SET @FormRead =’1,0,1,0,1,0,1,0,0,0,1,1,1,1,1,1,1,1,1,’
SET @FormWrite = ‘1,0,1,0,1,0,1,0,0,0,1,1,1,1,1,1,1,1,1,’

WHILE (CHARINDEX(‘,’, @FormId) > 0)
BEGIN

DECLARE @Form VARCHAR(30)
SET @Form = SUBSTRING(@FormId,0, CHARINDEX(‘,’, @FormId))
PRINT @Form

DECLARE @FRead VARCHAR(30)
SET @FRead = SUBSTRING(@FormRead,0, CHARINDEX(‘,’, @FormRead))
PRINT @FRead

DECLARE @FWrite VARCHAR(30)
SET @FWrite = SUBSTRING(@FormWrite,0, CHARINDEX(‘,’, @FormWrite))
PRINT @FWrite

INSERT INTO tbl_UserFormRights(Fk_UserId,Fk_FormId,[Read],Write)
VALUES(1,@Form,@FRead,@FWrite)

SET @FormId = SUBSTRING(@FormId, CHARINDEX(‘,’, @FormId) + 1, LEN(@FormId))
SET @FormRead  = SUBSTRING(@FormRead, CHARINDEX(‘,’, @FormRead) + 1, LEN(@FormRead))
SET @FormWrite  = SUBSTRING(@FormWrite, CHARINDEX(‘,’, @FormWrite) + 1, LEN(@FormWrite))

END

END