Saturday, March 26, 2011

Go to a Code Camp!!

I went to the Orlando .NET Code Camp this year (as well as last year) and picked up quite a few tid bits of information. They put on a great event and I even walked away with a few thousand dollars in software licenses for FREE. Can't beat that deal!

If you have an event in your area, I suggest you attend and who knows what you might get out of it :)

Wednesday, March 23, 2011

Finding a Control within a RadGrid Edit Template

I’ve recently needed to incorporate a RadGrid in which my edit template contained two RadComboBoxes. Depending on the value of my first combo box, the second would be updated with different sets of data. The problem I ran into was how to connect to this second combo box so I can bind it with data.

Here’s the basic premise:

RadComboBox combo1 = (RadComboBox)sender;
GridEditFormItem editItem = (GridEditFormItem)combo1.NamingContainer;
RadComboBox combo2 = (RadComboBox)editItem.FindControl("RadComboBox2");

And the more complete code sample here:


<telerik:RadGrid ID="RadGrid1" runat="server">
  <MasterTableView EditMode="EditForms">
    <EditFormSettings EditFormType="Template">
        <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadComboBox1_OnSelectedIndexChanged">
            <telerik:RadComboBoxItem Text="Selection 1" Value="1" />
            <telerik:RadComboBoxItem Text="Selection 2" Value="2" />
        <telerik:RadComboBox ID="RadComboBox2" runat="server">

Code-behind --

protected void RadComboBox1_OnSelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    RadComboBox combo1 = (RadComboBox)sender;
    GridEditFormItem editItem = (GridEditFormItem)combo1.NamingContainer;
    RadComboBox combo2 = (RadComboBox)editItem.FindControl("RadComboBox2");
       case "1":
          combo2.Items.Add(new RadComboBoxItem("Test"));
       case "2":
          combo2.Items.Add(new RadComboBoxItem("Test Again"));

Good luck :)

Wednesday, March 16, 2011

Calling a function in a ASP.Net User Control from another User Control on the same page

I recently had to develop a web application in which a page consisted of several user controls. One of the problems I encountered during the development of this page is that I needed User Control A to perform some bit of work, then pass of results and post them into User Control B.

I spent the better part of a day trying to find decent documentation on how to achieve this feat.

You would think you can simply do something like this from User Control A during a button click for example:

ControlB ctrlB = (ControlB)Page.FindControl("cB");
DropDownList ddl = ctrlB.ControlB_DDL;
txtDDLValue.Text = ddl.SelectedValue;

And as long as both controls are referenced on the page this works fine. Unfortunately this is not the case. This would be too easy. While this may work in some situations, it doesn’t seem to hold together well if master pages are used. And in my case nested master pages.

What to do… Well I continued researching and found several interesting articles about using delegates, event bubbling and all sorts of crazy things just to do one relatively simple task. Most of these articles (mostly blog entries) were so bad and hard to follow they aren’t worth reposting here.

In any event, I finally found a solution that worked for my needs. Instead of attempting something difficult and knowing .FindControl(..) wouldn’t work I found out about using .NamingContainer.

In my case my page consisted of a master page, a nested master page, an asp:Panel with an ID=”Data” on the page itself which housed my (destination)user control, and my user control in which I want to to modify data on, and finally the control itself living in that user control.

This code snippet is something I called during an InsertCommand event for a Telerik RadGrid control I happen to be using and takes the little info I want and adds it to a CheckBoxList control housed with my other user control.

CheckBoxList improvementsAddressed = (CheckBoxList)Grid_Improvement
improvementsAddressed.Items.Add(new ListItem(improvement, guid));


I could go into more elaborate detail, but since I’m new to this blogging thing, I’m not even sure if anyone will actually read it. Feel free to leave a comment if you need more details and/or help. But hopefully there’s enough info here to point you in the right direction to get you an elegant solution to your problem.

Instant Oracle Using C#

I’m amazed that people actually find the time to blog. I set this blog site up 2 or 3 weeks ago, have plenty of code to blog about but have been busy coding at my day job (and sometimes night job) that I haven’t had much time at all to even think about this.

Anyhow, the topic is about Oracle & C#, not my daily work load. I wrote up this article several years ago, when I actually did have more time and it’s apparently still getting plenty of good use today.

You can view the article here at Instant Oracle Using C#

I myself haven’t worked with Oracle databases for quite some time, but if you find you need to this article will help you get a project started.

Enjoy :)

Sunday, February 27, 2011

Ehhhh... Now what??

Ok, I've made it to the world o' blog...

Now what?!?! Guess I should blog about what I know best. Or at least can talk somewhat intelligently about. Well, that's the plan anyway...

At the very least, I may be able to share some of my expertise (or lack thereof) Who knows, I may be completely wrong, but either way somebody will learn something. Anyhow, this blog is inspired by an old post I made to a site called which has been helping millions of people in my profession with all things code.

The article I wrote entitled “Instant Oracle Using C#” is something I wrote after having created an application that needed to connect to a database. At the time, information on the subject was scarce so I thought I’d take a stab at it and I thought I did rather well. Having had over 150,000 page views in just under 4 years and 50-200 hits daily is pretty impressive given it’s just one article. So I thought I’d put this together so I can post bits of code I used to solve whatever problem I happen to be working on. Postings may be scare given time constraints of work & family life, but who knows… I may just post something that may just help you and that’s good enough for me!