Sunday, March 30, 2008

data table rowfilter (gridview filter)

protected void Button1_Click(object sender, EventArgs e)

{

DataTable dt = this.GridView1.DataSource as DataTable;


string filter = "field1='" + this.DropDownList1.SelectedItem.Text + "' AND " +

"field2='" + this.DropDownList2.SelectedItem.Text + "' AND " +

"field3='" + this.TextBox1.Text + "' AND " +

"field4='" + this.TextBox2.Text + "'";



dt.DefaultView.RowFilter = filter;

this.GridView1.DataBind();

}

remove duplicate row in datatable

Dim dt as new DataTable 'Assume this is the existing data table, populated somehow...
Dim dtNew as new DataTable
Dim dr as DataRow
Dim ID as Int32 = -1

dtNew=dt.Clone 'For having the same structure

for each dr in dt.Rows

If ID=-1 or ID <> Int32.Parse(dr("ID").ToString) Then
dtNew.ImportRow (dr)
ID = Int32.Parse(dr("ID").ToString)
End If

next

Hope this helps!!

Monday, February 4, 2008

Sharepoint 5 Feb 2008

http://www.sharepointblogs.com/
http://sharepoint.microsoft.com
Sharepoint Forms Authentication
http://www.dplouffe.ca/sharepoint-autnentication/

Forms Authentication with WSS 3.0 Tutorial

The following tutorial will demonstrate how to create an authentication script outside of the Sharepoint environment and implement the login within Sharepoint. You will learn how to use the fundamentals of Form Authentication as well as modify the Sharepoint Environment to enable Forms Authentication.

Luckily, if you are already an ASP.Net developer, you’ve most likely already played around with Forms Authentication. Since WSS 3.0 is built on top of Microsoft.Net 2.0, we can use the same fundamentals as ASP.Net to configure Sharepoint.

Required Tools
· Microsoft.Net 2.0/3.0

· Visual Studio

· WSS 3.0 Installation

· SQL Server database

Instructions
Creating your Authentication Web Site
Follow the steps below in order to create your authentication web site we will later use in the Sharepoint environment.

1. From you web/sharepoint server, create the following folder c:\VirtualDirectories\AuthSite.

2. Open the IIS Administration Panel and locate the web site for your Sharepoint Site installation.

3. On that website, create a Virtual Directory called AuthSite and point it to the newly created folder (Ensure that you check the Run Scripts checkbox on the last step of the Virtual Directory Creation Wizard).

4. Open Visual Studio 2005

5. Create a new website using C# as your coding language

6. Add a web.config file by right clicking on your website project and selecting Add New Item…

7. Select the Web Configuration file Option

8. From the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 folder, run the aspnet_sql.exe application. This application will guide you through creating the authentication database which we will use for our authentication scripts.

9. On the first screen, click on the Next button

10. On the second screen, ensure that the Configure Sql Server for Application Services option is checked and click on the Next button.

11. On the third screen, enter your database information. The user which you enter needs to have the rights to create a new database on the SQL Server. Leave the database name to . The wizard will create a database called aspnetdb automatically.

12. On the fourth screen, confirm the information you’ve entered and click on the Next button. The wizard will now created the necessary database.

13. Click on the Finish button when the wizard has completed.

14. Go back to Visual Studio 2005 and edit the web.config template you created in step 6.

15. Replace the node and replace it will the following code









Note: Replace the connectionString parameter with your own connection string.

16. Find the authentication node and replace insert Forms instead of Windows in the mode parameter.


17. From Visual Studio 2005 select the ASP.NET Configuration option under the top Website Menu. A browser window will open with the ASP.NET configuration tools.

18. Click on the security tab

19. Click on the Create user link in the Users menu.

20. Fill in the Create User form with a user of your choice.

21. Open the default.aspx template and add the Login Authentication object which can be found in the Toolbox.

22. Publish your website to a location of your choice.

23. Copy the content of the precompiled website to the folder you created in step 1.

Sharepoint Configuration
Now that your authentication website has been created, we are now ready to configure sharepoint in order to use Forms Authentication. Follow the steps below to configure Sharepoint.

Enabling Anonymous Access
1. Open the Sharepoint Central Administration from the Control Panel…Administrative Tools.

2. Click on the Application Management site on the top menu

3. Click on the Authentication Providers link under the Application Security menu.

4. Ensure that your Sharepoint site is selected in the Web Application drop down

5. Click on the Default link below the Zone heading.

6. Check the Enable Anonymous Access checkbox and click on the save button.

7. Open a new web browser and navigate to your Sharepoint site.

8. Select the Site Settings menu option from the Site Actions menu.

9. Click on the Advanced Permission link.

10. Click on the Settings button and select the Anonymous Access menu option.

11. Choose the Entire Web site option and click on the Ok button.

Configuration of Membership Provder
1. Open the web.config template located in your Inetpub\wwwroot\wss\VirtualDirectories\ folder.

2. Copy the connectionString node from you AuthSite web site and paste it into the Sharepoint web.config. Note: Paste it under the node to ensure that the application will compile successfully.

3. Go back to the Sharepoint Central Administration web site and go back to Authentication Providers. Follow the steps from 1 to 5 in the previous section.

4. Check the Forms radio box under the Authentication Type option.

5. Enter AspNetMembershipProvider in the Membership Provider Name text box.

6. Click on the Ok Save button.

7. Open a command prompt window and type the following command: iisreset

8. When the iisreset is done, open a new browser and navigate to your Sharepoint site.

You’ll now notice that you will not have to login in order to access your Sharepoint site. If you want to login, you can click on the Sign In link on the top left menu. You can use the user which you created in the AuthSite section in order to login to Sharepoint. By default, Sharepoint uses its own login script to authentication users. The next section will show you how to use your own site which we’ve created in the first section.

Configuration of Your Authentication Website
Now that we have Sharepoint configured to use Form Authentication we can configure it to use the website you created in the first step.

1. Open the web.config of your Sharepoint installation.

2. Find the node and replace it with the following code.



3. Go back to your Sharepoint website and sign out.

4. Click back on the Sign In link. You should be redirected to your new website.

Congratulations, you’ve just configured Forms Authentication with Sharepoint. Let me know if you have any feedback. Send it to dominic@dplouffe.ca

Sunday, February 3, 2008

4 Feb 2008 DELETE and Parent refresh

Delete


OnClientClick="return confirm('Are you sure you want to delete this record?');"
CommandName="Delete">Delete



window.close();
if (window.opener && !window.opener.closed) {
window.opener.location.reload();
}