Outside Computers

Sunday, October 14, 2012

Bind dynamically items in dropdownlists

In this tutorial I will show you how to bind items dynamically in dropdownlist.

in this example, i have used hyperlinks and bind the selected link in a single dropdownlist
I have used query string  for passing the value in the dropdownlist to show what items to be displayed.
you can also use session variables and also cookies for binding items on the list.

this is WebForm1.aspx

protected void Page_Load(object sender, EventArgs e)
        {
            createNavUrls();
        }
        private void createNavUrls()
        {
         
                HyperLink1.NavigateUrl = @"WebForm2.aspx?Option=1";
           
                HyperLink2.NavigateUrl = @"WebForm2.aspx?Option=2";
         
                HyperLink3.NavigateUrl = @"WebForm2.aspx?Option=3";
        }

this piece of code shows, when the page load, the code will call the createNavUrls(), that adds the navigate url links and shows the query string,, upon selecting on the links it has corresponding values,1,2,3 and the query string name is "Option".

WebForm2.aspx

 protected void Page_Load(object sender, EventArgs e)
        {
            filllist(Convert.ToInt32(Request.QueryString["Option"]));
        }
        private void filllist(int option)
        {
            ddlOptions.Items.Clear();
            if (option == 1)
            {
                ddlOptions.Items.Add("a1");
                ddlOptions.Items.Add("a2");
                ddlOptions.Items.Add("a3");
            }
            else if (option == 2)
            {
                ddlOptions.Items.Add("b4");
                ddlOptions.Items.Add("b5");
                ddlOptions.Items.Add("b6");
            }
            else if (option == 3)
            {
                ddlOptions.Items.Add("c7");
                ddlOptions.Items.Add("c8");
                ddlOptions.Items.Add("c9");
            }
        }

on the other hand, the second page will load, the selected hyperlink's value,

on the page load , the Request.QueryString["Option"], this will read the value given by the 1st page,
then on the method fill,  this will add the items that is selected on the desired input.

here is the sample url of the page.
"http://localhost:56594/WebForm2.aspx?Option=1"

Option is the querystring name and 1 is the value


i hope this code helps.






Tuesday, October 2, 2012

Adding table to a session

On this post I will show you ,how to add a table to a session and even add a new record, just like a Shopping cart in online shopping websites.

Here is a sample code for adding a table to a session and then rebinding it just like in shopping carts
private void GetData()
{
     try
        {
        DataRow[] dr = null;
        if (ViewState["SelectedRecords"] != null)
       {
            dt = (DataTable)ViewState["SelectedRecords"];
       }
       else
       {
            dt = CreateDataTable();    1:
        }
2
CheckBox chkAll = (CheckBox)gvAll.HeaderRow.Cells[0].FindControl("chkAll");
for (int i = 0; i < gvAll.Rows.Count; i++)
{
if (chkAll.Checked)
{
dt = AddRow(gvAll.Rows[i], dt);
}
else
{
CheckBox chk = (CheckBox)gvAll.Rows[i].Cells[0].FindControl("chk");
if (chk.Checked)
{
dt = AddRow(gvAll.Rows[i], dt);
}
else
{
dt = RemoveRow(gvAll.Rows[i], dt);
}
}
}
3.
ViewState["SelectedRecords"] = dt;
dtall = dt.Copy();
Session["CombineRecord"] = dtall;
}
catch (Exception ex)
{
}
this is your main method on how to add or remove items in your datatable, in this example I bound it to a gridview, which have a checkbox for adding or deleting items, this depends on the button clicked

1: means create a datatable
here is the code for creating a datatable
private DataTable CreateDataTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("ItemCode");
dt.Columns.Add("ItemDesc");
dt.AcceptChanges();
return dt;
}
2: this part shows what is the behavior if the checkbox is selected and what button is clicked, either add or remove, 
3: this part shows after selecting after modifying the datatable, you will then pass it to the viewstate named selectedrecords to hold it,
then dtall=dt.copy(); means that all records in the datatable dt is copied and moved to datatable named dtall
where dtall will either have an existing record or a new record
then pass dtall datatable to a session variable so that it will not be disposed after

After this,

private void BindSecondaryGrid()
{
gvCart.DataSource = (DataTable)Session["CombineRecord"];
gvCart.DataBind();
}
convert to datatable the session variable and bind it to your gridview.

This summarizes the passing of values to a session just like in Shopping cart

Monday, September 24, 2012

Mt. Pulag December Climb

Feel the Coldness in Mt. Pulag this December 21-24,as we will climb this mountain on the said date
plus be ware of the fees
this is just baguio-pulag-baguio trip
Guide - 100/head
Jeepney -9k roundtrip


For those who wants to join this adventure, you may put your comment guys,
Check your sched now as i will be updatting this post guys.


Thanks.







Sunday, September 23, 2012

Manabu Peak Night Trek

Guys, here is the Itinerary for the Manabu peak Night trek, that will happen on Oct 5-6 2012, but first here is the details of manabu peak

This peak is a part of Malipunyo mountain range, located in Sto. Tomas Batangas, its peak is marked by a white cross, and its trail is like a rosary, basically this mountain is for beginners and it has an easy trail.

below are the description of this peak

 Jump - off point :  Sulok, Brgy. Sta Cruz, Sto. Tomas
 LLA: 13.9777°, 121.2413°, 760 MASL
Days required / Hours to summit: 1 day / 1-2 hours
Specs: Minor climb, Difficulty 2/9, Trail class 1-2

Itinerary:

1800H : Robinsons Pala pala
1930H:: Fiesta mall Lipa, take trike to Sulok, brgy Sta Cruz
2000H: ETA Jump-off
2015H start Trek, Grotto Trail
2115H rest Grotto
2130H resume trek
2230H ETA Summit, Set up Camp , Socials
0030H Lights out
0600H Wake up Call , Breakfast , Explore Summit, picture taking
0900H break camp prepare , descent
1100H Jump off point, take a shower
1200H ETD to Fiesta mall
1300H fiesta mall , lunch
1500H Pala pala
1600H Home


For those who wants to join this adventure, you may put your comment guys

Thanks.








Monday, September 5, 2011

ASP.net Popup Window

On this post, i will give you a code snippet on how you can have a small popup window in your web application using asp.net

first what is a popup window, a popup window is just a small browser that shows some detailed information and often times ads, generally this new browser window is used for advertisements.

with us developers we can use this small popup for showing and minimizing file size, and even the whole page size, for showing what we need to tell the users.

basically popup window code is done through java script using
this code

window.open( URL, windowName[, windowFeatures] );

and since I am using c# in asp.net I use this code for the popup window

LinkButton1.Attributes.Add("onclick","window.open('Users.aspx','','height=300,width=300');return false");
on this code snippet , I have used a link button to open a new popup window, just put this on the page_load() event, and no need to have an event for LinkButton1_click().

i hope this helps, this is useful when you want to show a little information that needs less design and coding.



On my next post I will tell you how to pass values in different web pages, since web application is different in windows application. If you have suggestions and comment you can post it here. Thanks.

Monday, December 13, 2010

How to connect to a Database

Here is a sample code of how to connect to a database

this code is for microsoft access 2003

Imports system.Data.OleDb
Module Module1
    Public dbpath As String = Application.StartupPath + "\dbBilling.mdb"
    Public cnstring = "Provider = Microsoft.Jet.Oledb.4.0;Data Source =" & dbpath
    Public con As New OleDbConnection(cnstring)
End Module

sample Login in VB.net 2008

after a long long time of no post, here is a sample of login program in vb.net

this program have still bugs , and if you found one, post it here. Thanks


Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim ds As DataSet = New DataSet()
        Dim dr As OleDbDataReader
        Dim da As OleDbDataAdapter = New OleDbDataAdapter
        Try
            con.Open()
            Dim dc As OleDbCommand = New OleDbCommand("Select * From UserAccounts ", con) 
            dr = dc.ExecuteReader()
            With dr
                If .HasRows Then
                    While .Read()
                        If (.Item("UserName").ToString = UsernameTextBox.Text) And (.Item("Password").ToString                          = PasswordTextBox.Text) Then
                            Dim a As String = .Item("UserName").ToString
                            Dim a1 As String = .Item("Password").ToString
                            Form1.Show()
                            .Close()
                            Exit While
                        End If
                    End While
                    Dim b As String = .Item("UserName").ToString
                    Dim b1 As String = .Item("Password").ToString
                    MsgBox("Username or Password is Incorrect", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
                    UsernameTextBox.Text = ""
                    PasswordTextBox.Text = ""            
                End If
            End With
            con.Close()
        Catch ex As Exception
        End Try
        con.Close()
    End Sub


Monday, April 12, 2010

Java Founder Quits Oracle



The founder of JAVA language quits oracle after the Oracle bought the Sun Microsystems. Well for us James Gosling is the Father of Java since he is the one who made the java language.

Here are the details from another website v3.co.uk

James Gosling, considered by most to be the father of the Java programming language, has announced he is no longer working for Oracle.Gosling's unexpected departure follows that of Sun chairman Scott McNealy in January and Jonathan Schwartz a month later and backs up reports that the old guard at Sun are having trouble fitting into the new regime. Gosling refused to explain his sudden departure at this time.“Yes, indeed, the rumours are true: I resigned from Oracle a week ago (April 2nd),” said Gosling in his blog.
“As to why I left, it's difficult to answer: Just about anything I could say that would be accurate and honest would do more harm than good. The hardest part is no longer being with all the great people I've had the privilege to work with over the years. I don't know what I'm going to do next, other than take some time off before I start job hunting.”
He also apologised to TechDays attendees in St Petersburg, where he had been due to appear on Thursday, saying he hated not being there.Gosling joined Sun in 1984 and invented the original Java code, virtual machine and compiler. Hugely popular both inside Sun and among developers the loss of Gosling will be keenly felt, and will heighten concerns about Oracle's commitment to Java and open source coding.
 This will be a great loss. Since he is no longer works for the company who made java a great success.

Thursday, April 8, 2010

Upcoming Posts

On my next post, I will teach you on how to create a sample of a file maintenance system, and this will include  generation of reports. Also on my next post the softwares used is MS SQL Server 2005, VS 2005 and Crystal Reports 11. If you want to have this softwares just tell me and I am gladly to post the links for download of these softwares.

Sunday, March 28, 2010

Demonoid Codes

I will be giving 5 invitation codes. But please follow the rules and regulation of demonoid. In torrents mostly on demonoid, you cannot be always downloading files, you must be able to seed also, not LEECH, so if you cannot seed then you cannot join demonoid.

If you are willing to help to seed more in demonoid , i will give you the invitation code.

in order to give you the code you must comply with me.
1. Email me through your main email account
2. tell me your username
3. follow the rules
4. Contact info
you can email me here. lickweed_21@yahoo.com

Monday, March 22, 2010

Adding items in combo boxes from mysql database in vb.net

In this post, I will give some sample codes on how to populate your combo box from your database using datasets.

In this example code, I will use MYSQL as my database and VB.net 2005 teamsuite.

First part of the code: we write a code on setting up a connection on our database and here it is.
Dim dataset1 As DataSet = New DataSet
Dim dataadapter1 As MySqlDataAdapter = New MySqlDataAdapter

Dataset this is where we will put all the data that we will get from our datasources
Dataadapter this is our connection or bridge to our connection object and our dataset


2nd part : Getting the data from the database

Dim msql As String = "Select EmpId from tblempinfo" 'SQL query to select what data will be shown in the combo box
myda1.SelectCommand = New MySqlCommand(msql, mysqlcon) 'will trigger the selected sql query to get the data we needed


3rd Part: filling up the Combo box

myda1.Fill(myds1) 'the data adapter will fill our dataset to hold the data
cboEmp.DataSource = myds1.Tables(0) 'this code will connect the combo box and the database using datasets ,setting up a data source.
cboEmp.DisplayMember = "EmpId" 'this will filter what data to be displayed on the combo box
cboEmp.ValueMember = "EmpId" 'this will set or get the actual value of the displayed member.



I hope this sample code will help you

Enjoy Coding.



On the next post : setting up the reports from the selected value on the combo box

Thursday, March 18, 2010

Crystal Reports VB.net how to connect them

In this post, this will show you how to connect these 3 programs namely : VB.net , Crystal Reports XI, first is you can add a crystal report viewer object so that it can browse some crystal report files , then after adding the viewer, you can now set the report source of the viewer either by wizard or by coding it.

the sample code is like this


Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedIndex = 0 Then
Me.Close()
Form2.Show()
Form2.CrystalReportViewer1.ReportSource = Application.StartupPath + "\reports\CrystalReport3.rpt"
Else
Form2.Show()

this code above will set the report source or the report that will be printed on the report viewer depending on what the user selected in the combo box.

Form2.CrystalReportViewer1.SelectionFormula() = "{tblsched.EmpId} = '" & TextBox1.Text & "'"
Form2.CrystalReportViewer1.ReportSource = Application.StartupPath + "\reports\CrystalReport2.rpt"
End If
End Sub

the 2nd quoted code shows what data will be shown depending on the value of the textbox then you can choose what report will be printed by selecting an item in the combo box.


Note: You can add you created reports in the vb.net proj so that it will accept the application.startuppath code, you can place the reports inside the bin directory

if there's some problem in this tutorial just post here your comment or leave a message

enjoy coding!!

Wednesday, March 17, 2010

Welcome

Guys

this blog is all about helping newbie programmers out there, i hope this blog will help you and if you have some problems regarding in your programs you can post it here and i would gladly help you