Saturday, July 31, 2010
  Search
 
Register
Login
 
Getting Started with Code Endeavors Ajax Compiled Module Template
DotNetNuke Ajax development just got easy thanks to Jon Henning and his Ajax Compiled Module templates. He’s got them listed on CodePlex, they’re updated for DNN 5, and they are available in C# and V...

Find this article and more in the category

Read This Article . . .

Converting a CSS Template To a DotNetNuke Skin
Creating DotNetNuke Skins can be a time consuming task. But, it's really not that hard and it doesn't have to be if you can use templates to help get started. Why not convert some free templates from...

Find this article and more in the category

Read This Article . . .

More Ways to Install DotNetNuke Modules with the URL Method
While DotNetNuke has a built in mechanism for installing modules, there is another method you can use as well. This is a great alternative to use especially when you are trying to install larger mod...

Find this article and more in the category

Read This Article . . .

Everything You Never Wanted to Know About the Config File
This is the "pre-" first installment in a series that will cover the parts of the web.config file to give you an idea of how to manipulate and customize your DotNetNuke portal. The web.config fi...

Find this article and more in the category

Read This Article . . .

Upgrading to DotNetNuke Cambrian 5.0 from DotNeNuke 4.x
If you're looking to try out the new DNN Cambrian package, you can upgrade previous DotNetNuke installations with the following steps. Remember, as of right now, the DNN 5.0 Cambrian package availabl...

Find this article and more in the category

Read This Article . . .

Quick Check for Troubleshooting the CodeEndeavor Ajax Templates
I haven’t just installed the the template and created a module out of the box yet. However, I have come across a few things that I know to check and fix and I’m up and running in no time at all. If y...

Find this article and more in the category

Read This Article . . .

Installation from the DotNetNuke Install Package 4.90 to Windows XP Professional
OK, so you made the leap and downloaded an installation package of DotNetNuke 4.x.   But now what do I do?  Well, here's a step-by-step instruction guide to get you up and running with DotNetNuke 4....

Find this article and more in the Localhost category

Read This Article . . .

Installing DotNetNuke on the root of GoDaddy - 8 Simple Steps
If you have are having a hard time getting DotNetNuke installed on the root of your hosting account, read this article to find out how. This article was originally written for a the specific purpose ...

Find this article and more in the Hosting Provider category

Read This Article . . .

Resolving Troubles with DNN User Controls During Module Development & Compilation
So, you've created a module in a separate project using some DNN User Controls and now you're receiving errors and can't compile? If you are using these controls (list below) on your module using ...

Find this article and more in the category

Read This Article . . .

How to Install DotNetNuke 5.0 Cambrian and Video
 This video tutorial covers installing using the Custom installation option, with SQL Express and also an external SQL Database. Find out more about which package to download and how to kick off the ...

Find this article and more in the category

Read This Article . . .

Search for Articles

Virtual-Essential's DotNetNuke, .NET, and SQL Tips For the Developer

Minimize
Nov 15

Written by: Briana Tarrance
11/15/2008 4:46 PM 

Creating a gridview programmatically is easy. All you have to do is create the GridView object, bind data and add it to the page like this:

Dim GridView1 As New GridView
GridView1.DataSource = MyDataTable
GridView1.DataBind

MyPlaceholder.Controls.Add(GridView1)

This will give you a basic grid view that will provide textbox controls in the fields when the grid view is set to edit mode. If you drop a gridView object on a page, you will get the same results. In the codebehind, you would only have to use these lines:

GridView1.DataSource = MyDataTable
GridView1.DataBind

But, if you want to create a drop down list instead of a textbox in the gridview you can easily do this. Click on the smart tag for the gridview and go to click on "Edit Columns". Find the column that you want to change from a textbox and click on "Convert this field into a TemplateField".

Close the box and return to the smart tag options and click on "Edit Templates" Any columns that you have turned into templateFields will show up as on option in the new view (you may have to click on the smart tag again). Each templated column will have a view for the Item {read only/default view}, Edit {what you see when the grid view is in edit mode...you can make things read only, or invisible here if you don't want them to be seen in edit mode}, also templates for Insert {insert view of the gridview insert mode}, the Footer and Header also.

So, if you want to see a dropdownlist instead of a text box in the Item template for example, you can simply delete the text box. Replace it with a dropdownlist control, rebind the new control to the correct field (the control will have its own smart tag that says, "Edit Databindings"). Name the new control if you want to access it programmatically.

For this example, will name it DropDownList1 (original, yes, I know . So, in the code behind if you want to be able to access the information in that dropdownlist you could do the following:

Dim myDDL as DropDownList = CType(Me.GridView1.FindControl("DropDownList1"), DropDownList)
If Not myDDL is Nothing Then
myDDL.text = "Something I want it to say"
End If

As a note: you can add anything you want in these template fields. You can add a detailsView, FormView, whatever. You would access them programatically the same way. (me.gridview1.findcontrol("controlname")) then, you can access them. HINT: If you need to access a template field in a formview, for example, that is nested in a gridview template field you first need to "FindControl" the formview...then "FindControl" again the formview control.
 

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
 
 
Copyright 2008 by Virtual-Essentials.com Privacy Statement    Terms Of Use