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.