Tuesday, April 08, 2008

Locating Contributor settings inside Sharepoint Designer



Locating Contributor Settings inside Sharepoint Designer

Friday, March 07, 2008



HOW TO DEPLOY A WEBPART THAT HOSTS A WEB USER CONTROL TO SHAREPOINT

There are a couple of different ways to create the web part and deploy it to Sharepoint, but here is how I did it. In my case, I developed locally on my machine( I did copy the Sharepoint dlls locally for reference). The deployment server was on a virtual machine where I had MOSS setup.

1. Create the Web User Control(with code behind) in Visual Studio.

2. Sign the Assembly so that it has a strong name

3. Create the web part (either Sharepoint Webpart or ASPNET Webpart) in Visual Studio. Another good article for reference

4. Sign the Assembly.

5. Go to the Sharepoint Deployment Server.

6. Copy both the above strong named Assemblies(user control and webpart assemblies) to GAC on the Sharepoint server

7. Modify security settings of Sharepoint site by changing the Trust to Full in Web.Config of the Sharepoint Site like this..
trust level="Full" originUrl="" />

8. Add Safe Control Entries to the DLLs added to GAC in Web.Config of the Sharepoint Site similar to this.. ( I used Reflector to get the strong name)
SafeControl Assembly="SmartParticles, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=70d581d0b6a14330" Namespace="WebParticle" TypeName="*"
Safe="True" />
( I used Reflector to get the strong name)

9. Add an Assembly element to the assemblies section of Sharepoint site’s web.config file..similar to this.

assemblies><

add assembly="SmartParticles, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=70d581d0b6a14330"
/>

>
>


10. Create a Folder usercontrols under the Sharepoint site ex: wss/VirtualDirectories/80/usercontrols. Make sure this is not an application in IIS, as otherwise, it will fail.

11. Copy the ascx file(web user control file) and the other css files, xslt files and images(used by the user control) to this usercontrols folder. Make sure that when you access these other files from inside your user control code, they are referenced as “/usercontrols/*.gif” and so on.

How to populate the Web Part Gallery with the added Webpart.
The user needs to be the administrator of the site in order to do this.

Open the main Sharepoint site and go to Site Actions->Site Settings->Modify All Site Settings and click Webparts under Galleries.

Click New..this will by using Reflection populate the new webpart from the safe controls list in web.config.

Select the new web part and click “Populate Gallery” to place it in the gallery.

The webpart is now availableto populate on any of the Webpart pages inside Sharepoint.

See the webpart from my Test Sharepoint Site below:

Tuesday, February 12, 2008

Designing Reports with Reporting Services

The following blog has a good post on how to setup Reporting Services Add-in
http://blogs.threewill.com/implementingsharepoint/Lists/Categories/Category.aspx?Name=Reporting

Issue 1:

As I was working with designing reports, I had a scenario where I had to have a parameter with a dropdown of all the Locations that a user has access to. This is stored in SQL Server in my case. I was not sure how to do it. I knew I had to create a dataset that returns the locations and pass in the logged user. I did do that, but instead of passing User!UserID, I created another Report parameter called UserID and set that to User!UserID and passed this ReportParameter as the Dataset’s Query Parameter.

When I tried to do it like that, I ran in to an error. I searched for it and found the solution to the problem in the blog entry below. I had the Dataset Report Parameter declared above the UserID parameter. Fixing it as below, made the error go away.

Declare Parameter Y before X as below.
Go to the Layout tab
Select the Report object in the properties window
Go to the ReportParameters property and edit
Move Y above X using the arrows
http://blogs.infosupport.com/raimondb/archive/2006/08/09/sqlrepparamerror.aspx

Issue 2:

I had a need to conditionally sum the underlying data and display it in the group footer.
I followed the following advice from a forum and it worked.

Ex:=Sum(iif(Fields!Status.value = "Value a", Cdbl(Fields!Payment.Value), 0.0))

http://www.tek-tips.com/viewthread.cfm?qid=1072925&page=3


Issue 3:

I was trying to solve a problem by using an aggregate function and display it in the footer by using another aggregate function. It won’t work in Reporting Services as you cannot embed aggregate functions within each other, nor can you use a calculated field as an expression in an aggregation function.

I even considered using the technique below, but did not help.

http://www.codeprof.com/dev-archive/211/19-82-2111320.shtm

I finally solved my problem by using a Report Parameter instead.

Tuesday, November 27, 2007

WSS 3.0 and SQL Server Embedded Edition.

Here is a blog entry about this, which I found was useful.. I have'nt tried uninstalling it as mentioned here...but was good to know about it.

http://decipherinfosys.wordpress.com/2007/05/06/wss-and-sql-server-embedded-edition/


Related Forum entry that I found..
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=949426&SiteID=1

You can connect to the SQL Server Embedded Edition from Management Studio Express using the following as Server name..thanks to the above forum entry...
\\.\pipe\mssql$microsoft##ssee\sql\query

Tuesday, November 20, 2007

Setting Up Vista 32 Bit on a Virtual Machine

This was fun. I got a copy of Vista 32 Bit Ultimate Edition and was trying to decide if I wanted to load it as my main Operating System or not. Unfortunately we still had couple of application running on .NET 1.1 that needed to be upgraded. As I had to support them still, I had to create another environment (a virtual machine or use another physical machine) to host XP.
Not sure if it is a good decision or not, but I decided to create a virtual machine with Vista on it. I did not have any problems having that part work. But, after Vista loaded, I quickly found that my audio was not working....Tried installing various drivers, but to no avail. I then installed Virtual Machine Editions and rebooted my machine. This time,:) my audio worked!!!!

Tuesday, October 02, 2007

SQL Server 2005 Reporting Services
Service Pack 2

(Configuration Woes for Sharepoint Integrated Mode)

I finally got the SQL Server Reporting Services 2005 to run in Sharepoint Integrated Mode and can now see Reports.

Story:
We were evaluating Reporting Services and Sharepoint and wanted to see how well both of these technologies could help leverage our Business. So, tried to setup a Lab Environment. As I already mentioned in my previous blog entry, we had an Image of Windows Server 2003 SP2 and SQL Server 2005 SP2 with Reporting Services 2005 SP2 and MOSS 2007 loaded.

I started with this image and tried to set up the Integration Mode.
So, first downloaded the Reporting Services Addin here and installed it and configured the server per the documentation. I followed the links below:

http://technet.microsoft.com/en-us/library/aa905871.aspx

http://blogs.msdn.com/sharepoint/archive/2007/08/02/microsoft-sql-server-reporting-services-installation-and-configuration-guide-for-sharepoint-integration-mode.aspx

This second one above was extremely helpful when I went back and checked on some things that I overlooked the first time and configured later while I was troubleshooting below.


Issue 1
It appeared that the Addin installed fine, but when I went to look in the Central Administration, I could not find the Reporting Services Section under Application Management at all….what did I do wrong?

After some research, found out that if your Sharepoint Site Collection was not available or if the account you are using to install Reporting Services Addin does not have full control over that Site Collection(you are concerned about) when you install the Reporting Services Add-in, then the Reporting Services Integration Feature is not activated for that Site collection.

If you activate it, by doing the steps below for the site collection, you can see the Report Viewer webpart and also add Reporting Services Content Types.

http://blogs.msdn.com/rosettaue/archive/2007/04/06/how-to-activate-the-report-server-feature-in-sharepoint-central-administration.aspx

Okay…I uninstalled add-in and reinstalled with an account that was the Site Collection Adminitrator/Farm Administrator and Local Administrator of that machine. I could have done the above for my site collection in question and it would have worked.

After that I could see the Reporting Services section under Central administration. However, when I clicked on “Set Server Defaults” option is Central Administration, I was getting the following error:

Issue 2
An unexpected error occurred while connecting to the report server. Verify that the report server is available and configured for SharePoint integrated mode. --> Server was unable to process request. ---> The request failed with HTTP status 401: Unauthorized.

Looked all over internet and even posted the question to the forum. I followed the suggestions some people had in Brian Welckers Blog and couple others, but no luck.

I tried the following workarounds:

http://support.microsoft.com/kb/871179/en-us%20:%20Here%20I%20actually%20tried%20setting%20up%20my%20environment%20to%20“NTLM”%20(workaround)%20as%20I%20was%20working%20with%20an%20image%20and%20could%20not%20get%20the%20spn%20to%20work.: Here I actually tried setting up my environment to “NTLM” (workaround) as I was working with an image and could not get the spn to work.

http://stevenharman.net/blog/archive/2007/03/21/Avoiding-the-401-Unauthorized-Error-when-Using-the-ReportViewer-in.aspx: Here I even modified the registry, even though I was working with Windows Server 2003 SP2…which may not have needed this…

Issue 3
Well. I was tired of getting the above error message to go away and thought that as Set Server Defaults was just an optional requirement, I would go ahead and add the Report Viewer Web part to my Sharepoint Site. I was able to add the Report Viewer web part , but when I tried to create a shared data source or tried to choose an rdl to load the report viewer….I was getting an error 

Well, I tried a couple more things….

 I added SSRSWebAccount that I was using to run my Reporting Services Web Service (which also is my Report Server ApplicationPool account) to the Reporting Services Database (in my case the name of the database was OSS1) by going to the SQl Server Management Studio and manually assigning it. For some reason, it was not there to begin with.

 I gave RSExec permission to SSRSWindows Account on Reporting Services database.

 In Central Administration, I have Authentication Providers for my Site Collections set to Integrated Authentication..Kerberos…
 In Central Administration, Reporting Services -> manage integration settings… I have the Authentication Mode set up to Trusted Account.

None of this helped and suddenly I looked at the Reporting Services’ Database Version and noticed that it was 9.0.0.33. I knew that SP2 version was 9.0.03042. The version that was loaded on that image was the December, 2006 pre release version

So, what does it hurt…so I went and grabbed the latest released version of SP2 9.0.03042 and applied it on my server. After that I went back and filled in any missing configuration that I applied above. Most of it was already there.

Okay….tried now going to Set Server Defaults,…yippe…it worked…

Both of my above issues went away after I installed SQL Server 2005 SP2 9.0.03042.

It was strange that I did not have to setup spn’s even though I have my Site Collections as Integrated…Kerberos as stated was required somewhere in the docs… I still don’t completely understand that inner workings of all this…but it works well now.

Remember, all the workarounds that I applied (as stated in Issue2 and Issue3) on the server still remain. I did not undo any of that…so all that with the SP2(3042) may be what helped me solve this….

Good Luck to those of you….on your journey to Configuring Reporting Services in Integrated Mode.

Wednesday, September 19, 2007

Reporting Services

I am still having trouble getting Reporting Services to work in Sharepoint integrated mode. So, I decided to swap to native mode and try to display Reporting services Reports using WSS 2.0 Report Viewer and Report Explorer Web parts. All this I am doing in a test environment on an Image got from Microsoft, with MOSS 2007 and Reporting Services 2005 SP2 installed.

For this I followed the following article:
http://msdn2.microsoft.com/en-us/library/ms159772.aspx

However, when I tried to run the following, I was getting an error that said, it was already installed.

STSADM.EXE -o addwppack -filename "C:\ Program Files\Microsoft SQL Server\90\Tools\Reporting Services\ SharePoint\RSWebParts.cab" –globalinstall

But, I could not see the Report Viewer and Report Explorer Web parts in the “Add Web Parts” dialog box, when I tried to add them to my Sharepoint Site. I searched all over internet and found the following blog entry:

http://sqljunkies.com/WebLog/sqlbi/archive/2005/01/23/6802.aspx

I followed it and changed my STSADM command as below and ran it. In my case, as I had MOSS 2007 loaded on the same machine as Reporting Services SP2, the STSADM was found at: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN. So, I changed to this directory in command window and ran the following command.


STSADM.EXE -o addwppack -filename "C:\ Program Files\Microsoft SQL Server\90\Tools\Reporting Services\SharePoint\RSWebParts.cab" –url
http://mysharepointsite/



And :) it worked that time. It said it installed fine. When I went back to add web parts, I could now see both the Report Viewer and Report Explorer Web parts. Next, I followed the first article above and setup the Report Manager Url and Report Name properties for the Report Viewer webpart and can see the Report
fine.


See image below:

Wednesday, September 05, 2007

Network Connectivity from/to Virtual PC

As we were trying to understand how to use/implement and work with Sharepoint, few things were unveiled. We almost knew from the beginning that we had to use a Virtual PC environment for our development otherwise use another PC/Server with WIN2003 OS. But, were not sure exactly how to configure it.

When we finally got Microsoft Virtual PC 2007, loaded it up with an image that my friend got from TechEd-2007 with MOSS 2007 , Visual Studio 2005, Sql Server 2005 loaded on it.

All that was well. Now I needed to make my host machine and guest machine talk to each other. By default the Virtual Machine was using the the Shared Network from my local machine and I was able to connect to Internet from VM fine.

However, I could not see the file structure on my virtual machine from my host machine. I researched and found that I needed to install Microsoft Loopback Adapter on my host machine and configure it on my VM as the second network adapter, leaving the default Shared Network adapter as the first one on the VM. As soon as I did this, I could access my virtual machine like below from the Windows Explorer: file://myservername/C$ where myservername is the name of my virtual machine.

I used the following link to configure above:
This may not be the only way to see the Virtual Machine's file structure though and the only reason to install the loopback adapter. Still Learning.......:)

Friday, August 17, 2007

Sharepoint Musings

We were successfully able to load MOSS 2007 on a production box and have couple of sites up and running. Everything was working till the other day, a user complained that he could not find "Connect to outlook" and other Office integration options in the menu when he chose Calendar view on the calendar. There was also no "Datasheet View" on the All Events view of the calendar list. See image below:



Searched all internet and finally found a place in comments somewhere it was mentioned that Client Integration needed to be enabled in order to see this.

So, the solution was in Central Administration->Application Management->Authentication Providers--->Here there is an option to enable client integration. Enable this for the correct application and it works. The menus are now shown as expected.

Next, when I was testing the datasheet option, it wouldn't export but gave me an error stating that the wss Datasheet component was not correctly loaded....

Apparently, the problem was I did not have Office 2007 loaded on my client PC. The web datasheet option is only available if you have Access 2007 on your client machine. However, later I found the following article and followed it.

http://support.microsoft.com/kb/833714

I installed sharepoint support to my installed Office application as above and the datasheet option now works just fine.

Wednesday, May 30, 2007

Encrypt Config Sections in ASP.NET 2.0
(Encrypt Connection Strings in web.config using RSA and machine level containers)

This article assumes the user is using Visual Studio.NET 2005 Web server and wants to use the default provider with default settings. The RSAProtectedConfigurationProvider is the default provider and is configured to use the machine level key container.

Encryption:



  • Add a connection string section with a connection string in regular text in the local web.config file of your application.

  • Run the following command to encrypt (should be run from Visual Studio 2005 command prompt).

aspnet_regiis -pef "connectionStrings" c:\projects\RSAEncryptSample

Note: The third segment in the command after -pef is the section in the web.config file that you want to encrypt. The fourth segment in the command is the location of the config file whose section you want to encrypt. aspnet_regiis utility is located at %WinDir%\Microsoft.NET\Framework\'versionNumber'\. As the default provider with default settings is selected, wedo not need to use the -prov switch in the command.

And that's it the section is encrypted and your web.config file is changed with the new encrypted stuff.

Accessing Encrypted Connection String:

  • ASP.NET automatically handles the decryption in this case. All you have to do to see the connection string in text is ...somewhere in your code..like in page_load..put the following code and run the web application and you should the connection string in text.

Response.write("Connection string in Text" & ConfigurationManager.ConnectionStrings("myLocalSqlServer").ConnectionString.

Decryption :

  • Run the following command(from Visual Studio 2005 Command prompt) to decrypt the above encrypted section back.
aspnet_regiis -pdf "connectionStrings" c:\projects\RSAEncryptSample

Thursday, May 17, 2007

ASPNETDB Database in ASP.NET

The membership database ASPNETDB is automatically created under APP_Data folder when we set the Connection string for the Membership Provider in the web.config to be "LocalSqlServer" and run that web project the first time. We may see the contents of this database by attaching the created database to your local instance of SQLExpress and using Management Studio.

Alternately, we may run the aspnet_regsql.exe tool from Visual Studio 2005 prompt and it will step us through creating a new membership database on the server (SQL Server 2005 or SQL Express) wherever we ask it to in the wizard. We ofcourse would have to create a new connection string(that looks at this database) and point the membership provider to look at this new connection string in the web.config file of the respective project.

Monday, May 22, 2006

ASP.NET 1.1 and 2.0 installed on same machine.

I ran in to this error the other day when I installed Visual Studio 2005 on my machine and tried to debug a web project written in (.NET 1.1) and in .NET 2003 IDE.

“Unable to start debugging on the web server”

The following article was useful for checking some things.


I tried to repair .NET Framework 1.1 , adding the http://localhost to trusted sites group.

However, nothing helped me.

I then tried to go to IIS-> My Web Project node and rtclick and go to Properties window.
There, I clicked on General Tab -> Configuration button, this brought up an Application mappings window, which had .aspx resolved to 2.0 framework’s isapi dll, I changed it to point to 1.1 framework’s isapi dll and everything started working.

I hope this helps somebody there.

Thursday, May 11, 2006

Tomato Soup

I hate to mix cooking with technical stuff that post on this blog...but cant help it....I made tomato soup last night and it came out dramatic...I was very pleased with myself... I used the following recipe.


1 lb. Tomato(ripe)
2 tbsps.
Sugar
1 tbspn Salt(or as required)
3 pinches Garam Masala powder
¼ tsp.
Red Chili Powder
1 tsp.
Butter or ghee
½ tbsp. All Purpose Flour

Method:

Boil the tomatoes till they are soft when you prick with a fork.

Remove peels..they should come off easily once boiled.

Blend till smooth. Strain to remove seeds.

Heat butter in a pan(or use ghee), add garam masala powder and fry for a few seconds.

Add tomato puree. Stir.

Dissolve the flour (maida) in a little water till smooth. Add the flour paste, stirring continuously, bring to a boil.

Add the seasoning, salt and sugar. Simmer for 5-7 minutes.

Serve hot with bread croutons, a swirl of fresh cream, and pepper.

XML Webservices .NET 1.1 Certification

I recently passed another MCP exam (.NET Web Development) in Visual Basic. That gets me 2 MCP's ....not sure when I will take the third certification in XML web services.... I hope to take it pretty soon this year and get done with it...

Tuesday, December 13, 2005

Implemeting HTTP Modules in ASP.NET

I have found the following article very useful in getting started with creating/using HTTP Modules.

http://www.15seconds.com/issue/020417.htm

Friday, December 02, 2005

Accessing from multiple SourceControl locations.

I recently had to access code from "Sourcegear Vault" and at the same time access from "Visual Sourcesafe". This caused a problem to me as we can have only one default sourcecontrol in Visual Studio. Fortunately, one of my friends directed me to this place ,
where I found the an app that changes the default sourcecontrol in Visual Studio in oneclick.

http://weblogs.asp.net/mlafleur/archive/2003/06/17/8812.aspx

I however have to remember to do it, before I access projects from the respective sourcecode locations.

Wednesday, November 30, 2005

Javascript Issues


I am not sure why, but when I use the following function, if there is only one checkbox, it is not working. When I try to use alert and see the contents of attendeelength, it is returning undefined. Note: This happens only when I have one checkbox by name “attendees”, but if I have multiple checkboxes with same name, code works fine.

function CheckAll()
{
var count=0;
var attendeecheckbox = document.all.item("attendees");
var attendeelength = document.all.item("attendees").length;
while (count != attendeelength) {
attendeecheckbox(count).checked=true;
count++;
}
}



So, my solution was to use the following code instead of the above code. This code works with one or many checkboxes.

function CheckAll()
{
var count=0;
var attendeecheckbox = document.getElementsByName("attendees");
var attendeelength = attendeecheckbox.length;
while (count != attendeelength) {
attendeecheckbox(count).checked=true;
count++;
}
}

Thursday, November 10, 2005






Dynamic Vertical DataGrid

The following is an illustration of how to create a dynamic vertical datagrid. The problem I had was to allow users to enter Goals in one column while displaying the Scores in another column and save the data in to database. The scores were already available in the database.

Also, the number of columns in the datagrid had to be dynamic as the bonus objectives would change every year. The other issue was I had to let users score the Goals they put in another column.

To accomplish this, my solution was to create a dynamic vertical datagrid. The final output looks like the above grid

For this I created a DataGrid Template class as shown below, which is the heart of the solution.

Public Class myDataGridTemplate
Implements ITemplate
Dim templateType As ListItemType
Dim columnName As String
Dim columnControlID As String
WithEvents dgrid As DataGrid
Dim dgridid As String
WithEvents lbl As Label
WithEvents lc As Literal
WithEvents tb As TextBox
WithEvents cb As CheckBox

Sub New(ByVal type As ListItemType, ByVal ColName As String)
templateType = type
columnName = ColName
End Sub

Sub New(ByVal type As ListItemType, ByVal ColName As String, ByVal ColControlID As String)
templateType = type
columnName = ColName
columnControlID = ColControlID
End Sub

Sub New(ByVal type As ListItemType, ByVal ColName As String, ByVal mygrid As DataGrid, ByVal gridid As String)
templateType = type
columnName = ColName
dgrid = mygrid
dgridid = gridid
End Sub

Private Sub InstantiateIn(ByVal container As Control) _
Implements ITemplate.InstantiateIn
Dim lc1 As New Literal
lc = New Literal
lbl = New Label
Select Case templateType
Case ListItemType.Header
lc1.Text = "" & columnName & ""
container.Controls.Add(lc1)
Case ListItemType.Item
If columnName = "innergrid" Then
dgrid.ID = dgridid
container.Controls.Add(dgrid)
Else
lbl.ID = columnControlID
lbl.Width = New Unit(40, UnitType.Pixel)
container.Controls.Add(lbl)
AddHandler container.DataBinding, AddressOf BindData
End If
Case ListItemType.EditItem
If columnName = "Achieved" Then
cb = New CheckBox
cb.ID = columnControlID
cb.Width = New Unit(20, UnitType.Pixel)
container.Controls.Add(cb)
AddHandler container.DataBinding, AddressOf BindCheckBoxContents
Else
tb = New TextBox
tb.ID = columnControlID
tb.Width = New Unit(45, UnitType.Pixel)
container.Controls.Add(tb)
AddHandler container.DataBinding, AddressOf BindTextBoxContents
End If
Case ListItemType.Footer
lc1.Text = "Footer"
container.Controls.Add(lc1)
End Select
End Sub

Private Sub BindData(ByVal sender As Object, ByVal e As EventArgs) Handles lbl.DataBinding

Dim container As DataGridItem = CType(lbl.NamingContainer, DataGridItem)
Dim dview As DataRowView = CType(container.DataItem, DataRowView)
Dim str As String = dview.Item(columnName).ToString()
lbl.Text = str
lbl.ForeColor = Color.DarkSlateGray

Dim istargetlinescore As String = dview.Item("IsTargetlineScore").ToString()
If RTrim(istargetlinescore) = "Y" Then
lbl.BackColor = Color.PeachPuff
End If
End Sub

Private Sub BindTextBoxContents(ByVal sender As Object, ByVal e As EventArgs) Handles tb.DataBinding

Dim container As DataGridItem = CType(tb.NamingContainer, DataGridItem)
Dim dview As DataRowView = CType(container.DataItem, DataRowView)
Dim str As String = dview.Item(columnName).ToString()
tb.Text = str
If RTrim(str) = "0" Then
tb.ForeColor = Color.RoyalBlue
Else
tb.ForeColor = Color.Crimson
End If
tb.Font.Bold = True
Dim istargetlinescore As String = dview.Item("IsTargetlineScore").ToString()
If RTrim(istargetlinescore) = "Y" Then
tb.BackColor = Color.PeachPuff
End If
End Sub

Private Sub BindCheckBoxContents(ByVal sender As Object, ByVal e As EventArgs) Handles cb.DataBinding

Dim container As DataGridItem = CType(cb.NamingContainer, DataGridItem)
Dim dview As DataRowView = CType(container.DataItem, DataRowView)
Dim str As String = dview.Item(columnName).ToString()
If RTrim(str) = "T" Then
cb.Checked = True
Else
cb.Checked = False
End If


End Sub

Private Sub dgrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgrid.ItemDataBound

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim curRadio As MetaBuilders.WebControls.RowSelectorColumn.ParticipantRadioButton
Dim lblScore As Label
curRadio = CType(e.Item.FindControl("RowSelectorColumnSelector"), MetaBuilders.WebControls.RowSelectorColumn.ParticipantRadioButton)
lblScore = CType(e.Item.FindControl("Label2"), Label) 'hardcoded the controlid

If (Not (curRadio Is Nothing)) And (Not (lblScore Is Nothing)) Then 'do this radio checking and color change only if the concerned controls are found in the grid
Dim container As DataGridItem = CType(curRadio.NamingContainer, DataGridItem)
Dim dview As DataRowView = CType(container.DataItem, DataRowView)
Dim str As String = dview.Item("Achieved").ToString()
If RTrim(str) = "T" Then
curRadio.Checked = True
lblScore.ForeColor = Color.Crimson
lblScore.BackColor = Color.Yellow
Else
curRadio.Checked = False
lblScore.ForeColor = Color.RoyalBlue
End If
Dim lblGoal As Label
lblGoal = CType(e.Item.FindControl("Label1"), Label) 'hardcoded the controlid
If RTrim(lblGoal.Text) = "0" Then
curRadio.Disabled = True
Else
curRadio.Disabled = False
End If
End If

End If

End Sub

End Class







The .NET code to build the dynamic DataGrid is as follows.

Public Sub BuildMainGrid()

PlaceHolder1.Controls.Clear()
Dim MainGrid As New DataGrid
MainGrid.ID = "MainGrid1"
Dim dl As BM_Datalogic = New BM_Datalogic
MainGrid.AutoGenerateColumns = False

Dim curempid As String
curempid = “123456789”

Dim iyear As Integer = “2006”
Dim strempid As String = “123456789”

Dim strname As String =”Orlando Quiroz”
Dim strunit As String = “4555”
Dim strjobtitle As String = “CHEF”


Dim gpds As DataSet = dl.FetchBM_GlobalParams(iyear)
Dim mdvDisplayFields As DataView = gpds.Tables(0).DefaultView
Dim i As Integer
Dim dr As DataRow
Dim tc As TemplateColumn
Dim spds As DataSet = New DataSet

'For each row in the global_params resultset...Fetch the subparams for each globalparam ***
For i = 0 To mdvDisplayFields.Count - 1
dr = mdvDisplayFields.Item(i).Row
spds = dl.FetchEmployeeSubParams(iyear, strunit, strempid, strjobtitle, dr.Item("Global_ParamNo"))
Dim mdvSubDisplayFields As DataView = spds.Tables(0).DefaultView
Dim spdr As DataRow
Dim spi As Integer
Dim no_o_subparams As Integer = mdvSubDisplayFields.Count
'For each row in subparams...add a template column and set the header text
For spi = 0 To no_o_subparams - 1
spdr = mdvSubDisplayFields.Item(spi).Row
tc = New TemplateColumn
If no_o_subparams = 1 Then
tc.HeaderText = "


" & CStr(spdr.Item("SubParamDescription")) & "
(" & CStr(spdr.Item("Sub_ParamWeightage")) & "%)



"
Else
If spi = 1 Then
tc.HeaderText = "


" & CStr(dr.Item("Global_ParamDesc")) & "(" & CStr(dr.Item("Global_Param_Weightage")) &amp;amp;amp;amp;amp;amp;amp;amp; "%)" & "
" & CStr(spdr.Item("SubParamDescription")) & "(" & CStr(spdr.Item("Sub_ParamWeightage")) & "%)



"
Else
tc.HeaderText = "


" & CStr(spdr.Item("SubParamDescription")) & "(" & CStr(spdr.Item("Sub_ParamWeightage")) & "%)



"
End If

End If

'For each row in the ***subparams resultset, build a goal,score datagrid and set the same itemtemplate to that grid.
Dim global_paramno As Integer = dr.Item("Global_ParamNo")
Dim sub_paramno As Integer = spdr.Item("Sub_ParamNo")

Dim goalscoregrid As DataGrid = New DataGrid
goalscoregrid = FetchTemplatedInnerGrid(iyear, strunit, Trim(strempid), Trim(strjobtitle), global_paramno, sub_paramno)

tc.ItemTemplate = New ValleyBonusMatrix.myDataGridTemplate(ListItemType.Item, "innergrid", goalscoregrid, "DataGrid1" & global_paramno & sub_paramno)
goalscoregrid.DataBind()
MainGrid.Columns.Add(tc)
Next
Next

MainGrid.DataSource = gpds.Tables(0)
PlaceHolder1.Controls.Add(MainGrid)
MainGrid.DataBind()
dl.closeconnection()

End Sub





Private Function FetchTemplatedInnerGrid(ByVal iyear As Integer, ByVal strunit As String, ByVal strempid As String, ByVal strjobtitle As String, ByVal paramno As Integer, ByVal subparamno As Integer) As DataGrid

Dim DataGrid1 As New DataGrid
DataGrid1.ID = "DataGrid1" & paramno & subparamno **This is important for saving
DataGrid1.AutoGenerateColumns = False

Dim dl As BM_Datalogic = New BM_Datalogic
Dim bpds As DataSet = dl.FetchBM_BonusPotential(iyear, strunit, Trim(strempid), Trim(strjobtitle))
Dim gpds As DataSet = dl.FetchBM_GoalScoreConfig(iyear, strunit, Trim(strempid), Trim(strjobtitle), paramno, subparamno)
dl.closeconnection()
DataGrid1.DataSource = gpds.Tables(0).DefaultView

Dim tc1 As New TemplateColumn
Dim curcolname As String = "Goal"
tc1.HeaderTemplate = New _
ValleyBonusMatrix.myDataGridTemplate(ListItemType.Header, curcolname)
tc1.ItemTemplate = New _
ValleyBonusMatrix.myDataGridTemplate(ListItemType.EditItem, curcolname, "TextBox1")
DataGrid1.Columns.Add(tc1)

Dim tc2 As New TemplateColumn
Dim curcolname1 As String = "Score"
tc2.HeaderTemplate = New _
ValleyBonusMatrix.myDataGridTemplate(ListItemType.Header, curcolname1)
tc2.ItemTemplate = New _
ValleyBonusMatrix.myDataGridTemplate(ListItemType.Item, curcolname1, "Label1")
DataGrid1.Columns.Add(tc2)

If bpds.Tables(0).Rows.Count > 0 Then
lblBonusPotential.Text = bpds.Tables(0).Rows(0).Item("BonusPotential").ToString
Else
lblBonusPotential.Text = 0
End If

Return DataGrid1

End Function

I call the BuildMainGrid function on my page load as follows:


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

BuildMainGrid()
End Sub




Note: I have included some of my project specific datalayer calls, which I marked in plum. You will have to replace that with your own logic or information. If saving is important to you, naming the dynamic grids unique is important. I came up with my own unique naming rules. See Red underline in FetchTemplatedInnerGrid function. You may use a different parameter, specific to your project to achieve the same.


Code to save the data from this datagrid is as follows:

Public Sub SaveGridData()

ErrLabel.Text = ""
Dim dl As New BM_Datalogic
Dim vpe As ValleyPE.clsSecurity = New ValleyPE.clsSecurity
Try
Dim iyear As Integer = ddlYear.SelectedItem.Value
Dim strempid As String = ddlEmployee.SelectedItem.Value

Dim strunit As String = txtUnit.Text
Dim struserid As String = vpe.UserName(Request)
Dim strjobtitle As String = ddlJobTitle.SelectedItem.Value
Dim dBonusPotential As Double = Convert.ToDouble(lblBonusPotential.Text)

Dim i As Integer
Dim j As Integer
Dim maing As DataGrid = New DataGrid
maing = CType(PlaceHolder1.FindControl("MainGrid1"), DataGrid)
Dim dgi As DataGridItem

Dim griditemcount As Integer = maing.Items.Count

'the second item in the maingrid holds the inner grids.
dgi = maing.Items(griditemcount - 1)

Dim gpds As DataSet = dl.FetchBM_GlobalParams(iyear)
Dim dr As DataRow
For Each dr In gpds.Tables(0).Rows
Dim paramno As Integer = dr.Item("Global_ParamNo")
Dim spds As DataSet = dl.FetchBM_SubParams(iyear, paramno)
Dim spdr As DataRow
'For each subparam of the current globalparamno
For Each spdr In spds.Tables(0).Rows
Dim subparamno As Integer = spdr.Item("Sub_ParamNo")
Dim innergrid1 As DataGrid = CType(dgi.FindControl("DataGrid1" &amp;amp;amp;amp;amp;amp;amp; paramno & subparamno), DataGrid)
Dim dginneritem As DataGridItem
Dim inneri As Integer
Dim iscore As Double
Dim igoal As Double
Dim lblscore As Label
Dim txtgoal As TextBox
For inneri = 0 To innergrid1.Items.Count - 1 'this contains the actual goal score contents
dginneritem = innergrid1.Items(inneri)
txtgoal = CType(dginneritem.FindControl("TextBox1"), TextBox)
lblscore = CType(dginneritem.FindControl("Label1"), Label)
iscore = Convert.ToDouble(lblscore.Text)
igoal = Convert.ToDouble(txtgoal.Text)
'Update Goal Score Config here
dl.SaveBM_ScoresConfig(iyear, strunit, strempid, strjobtitle, paramno, subparamno, igoal, iscore, struserid)
Next
Next
Next
'Save Goal Submission Information in Submission Table.
dl.SaveGoalsSubmissionInfo(iyear, strunit, strempid, strjobtitle, dBonusPotential, struserid)
BuildMainGrid()
dl.closeconnection()
Catch ex As Exception
dl.closeconnection()
ErrLabel.Text = ex.Message
ErrLabel.Visible = True
Exit Sub
End Try


End Sub