Tuesday, May 24, 2011

just a thought

जिस दिन मंदिर की घंटी से स्वर मिल गया अज़ान का
उस दिन रूप बदल जायेगा अपने हिंदुस्तान का

Monday, May 16, 2011

Setting gridview edititemtemplate dropdownlist selectedvalue

This is a very quick way of setting the selectedvalue of dropdownlist in gridview edittemplate...

Just add the following to your dropdownlist

SelectedValue='<%# Bind("acceptance") %>' AppendDataBoundItems="true"


The entire column would look something like this




<asp:TemplateField HeaderText="Acceptance">

                <ItemTemplate>

                    <asp:Label ID="Acceptance" runat="Server" Text='<%# calcAcceptance((int) Eval("acceptance")) %>'  />

                </ItemTemplate>

                <EditItemTemplate>

                <asp:DropDownList ID="ddlAcceptance" runat="server"  SelectedValue='<%# Bind("acceptance") %>' AppendDataBoundItems="true">

                    <asp:ListItem Value="0">Acceptable</asp:ListItem> 

                    <asp:ListItem Value="1">Required</asp:ListItem> 

                </asp:DropDownList>

                </EditItemTemplate>

            </asp:TemplateField>




Wednesday, May 11, 2011

Posting Html code to blogger/blogspot

http://www.simplebits.com/cgi-bin/simplecode.pl

This is a simple but superb utility which lets you customize your html for posting to blogger !!!

Seal of approval from me...

I can be definitely not be the only person who thinks of a seal nodding approvingly every time they say seal of approval... am I ??

Placeholder dynamic controls

So, I had to build on what I started yesterday.

Now I have a spiffy code sample for all the times when I want to add dynamic controls to placeholders..

The sample below adds 5 rows to a table with all kinds of funky controls each having its own properties set separately....

Here it goes ....drumroll !!!!!!

Front End


 <table class="sofT" style="width: 100%">
        <tr>
            <td class="SubClass">
                Course #
            </td>
            <td class="SubClass">
                Course Title
            </td>
            <td class="SubClass">
                Hours
            </td>
            <td class="SubClass">
                Grade
            </td>
            <td class="SubClass">
                Grade Pt.
            </td>
        </tr>
 <tr>
            <td>
                <asp:Label ID="lblCrNo5" runat="server"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="tbCrNo5" runat="server" Width="300"></asp:TextBox>
            </td>
            <td>
                <asp:TextBox ID="tbHrs5" runat="server" Width="30" Text="0.00"></asp:TextBox>
            </td>
            <td>
                <asp:DropDownList ID="ddlHrs5" runat="server">
                </asp:DropDownList>
            </td>
            <td>
                <asp:TextBox ID="tbGPA5" runat="server" Width="30" Text="0.00" Enabled="false"></asp:TextBox>
            </td>
        </tr>
        <asp:PlaceHolder ID="plCols" runat="server"></asp:PlaceHolder>
    </table>
 <asp:Label ID="lblCounter" runat="server" Visible="false"></asp:Label>
  <hr />
          <asp:Button ID="btnAdd" runat="server" CssClass="btn" Text="Add More Classes"
                    onclick="btnAdd_Click" />



And in the backend 



  protected void Page_Load(object sender, EventArgs e)
    {
        if (Cache["tt"] != null)
        {
            Panel tt = Cache["tt"] as Panel;
            plCols.Controls.Add(tt);


        }
}


 protected void btnAdd_Click(object sender, EventArgs e)


    {
            Panel tt = new Panel();
     
        int courseCounter = Convert.ToInt32(lblCounter.Text);


//this is a fix needed else 5 gets repeated twice.... 
        if (courseCounter == 5)
            courseCounter = 6;


        int numlabels = courseCounter + 5;


//this is getting the data for dropdownlist 
        DataTable ddlTable = createDdlTable();


        for (; courseCounter < numlabels; courseCounter++)
        {


            DropDownList ddl = new DropDownList();


            // Set the label's Text and ID properties.
            ddl.DataSource = ddlTable;
            ddl.DataTextField =  "hrsToShow";
            ddl.DataValueField = "hrsToShow";
            ddl.ID = "ddlHrs" + courseCounter;
            ddl.DataBind();
           
            Label lbl = new Label();
            lbl.ID = "lblCrNo"+courseCounter;
            lbl.Text = courseCounter.ToString();


            TextBox tb = new TextBox();
            tb.ID="tbCrNo"+courseCounter;
            tb.Width= 300;


            TextBox tb1 = new TextBox();
            tb1.ID="tbHrs"+courseCounter;
            tb1.Width= 30;
            tb1.Text = "0.00";


            TextBox tb2 = new TextBox();
            tb2.ID="tbGPA"+courseCounter;
            tb2.Width= 30;
            tb2.Text = "0.00";
            tb2.Enabled=false;


      //I know all this can be single Add... divided it for clarity !!
            tt.Controls.Add(new LiteralControl(""));
            tt.Controls.Add(lbl);
            tt.Controls.Add(new LiteralControl(""));
            tt.Controls.Add(tb);
            tt.Controls.Add(new LiteralControl(""));
            tt.Controls.Add(tb1);
            tt.Controls.Add(new LiteralControl(""));
            tt.Controls.Add(ddl);
            tt.Controls.Add(new LiteralControl(""));
            tt.Controls.Add(tb2);
            tt.Controls.Add(new LiteralControl(""));
            plCols.Controls.Add(tt);
            Cache["tt"] = tt;
        }


        ddlTable.Dispose();
        lblCounter.Text = numlabels.ToString();
    }



And as Disney says ...THATS ALL,  FOLKS !!


Hope to add the processing of dynamic controls thus added to tomorrow's post

I dont miss you

ज़िदों ने तर्क-ऐ-तालुक कर लिया लेकिन
सुकून उसे भी नहीं, बेकरार मै भी हूँ
ज़बान कहती है सारा कसूर उसका था
ज़मीर कहता है कुछ ज़िम्मेदार मै भी हूं

Tuesday, May 10, 2011

How to retain all of the dynamically added asp controls


The asp.net doesn't keep control state.
So if you want to create control dynamically, you should create the dynamic control every time in Page_Load function.
You can store the dynamic control into cache, and then read it at page_load function.
Here is a example, maybe help you.
    protected void Button4_Click(object sender, EventArgs e)
    {
        Panel tt = new Panel();
        TextBox tb = new TextBox();
        tb.ID = "txtName";
        tb.Text = "hello";
        tt.Controls.Add(tb);
        PlaceHolder2.Controls.Add(tt);
        Cache["tt"] = tt;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Cache["tt"]!=null)
        {
            Panel tt = Cache["tt"] as Panel;
            PlaceHolder2.Controls.Add(tt);
        }
    }


Update only month and day of a date in SQL server

Well..sometimes Woopse happens...

We had begin dates and end dates in our database ....well somehow they got all wrong dates... years were correct and hence began the update process


Update TableName
Set End_Date =CONVERT(datetime, Convert(varchar(4),DATEPART(Year, End_Date))+'-05-01 00:00:00.000')
where (DATEPART(MONTH, End_Date)='05' and DATEPART(DAY, End_Date) != '01')

Spiffy !!!

Also, my running is going awesome... SO far so good 

Friday, May 6, 2011

100 days 20 pounds challenge

Ah.. am a usual average nerd who spends 10-15 hours each day on the computer, typing away to nothingness...and rejoicing in my daily intake of mountain dew, pizza and cheetos !!!

But all good things come to an end and my happy coding world crumbled down yesterday when one of my friends asked me if I was expecting a baby !!!

NO ..NO ...NO ..NO ...no no no ..NO ..NO ... and if I didn't make myself clear... OH HELL TO THE NO !!!

After that rude awakening, I have decided what I should have done long time ago. No more occasional saunterings to the gym..no more half hearted jogs... Am going 300 !! SPARTAAAAAAAAAAAAAAAAAAAAAA !!!!

I am going to run/workout every day for next 100 days ...Goal is to drop 20 pounds by the end of it.

20 pounds you say !! A very small goal !! Not for someone 5 feet 2 inches tall....

Its a ginormous task for mini me !!

And it all starts today...My plan is to workout every day and document my progress right here..

I was going to post before and after pictures but that would be too cliche.. NO ?

Let me think about that... meanwhile, 2 miles here I come  !!!

Wednesday, May 4, 2011

string format 2 decimal places

Sometimes, little things take longer than most big complicated humongous functions.

All I wanted to do was to create a datatable with formated 2 places of decimals and it wasnt working... for hours


private DataTable createDdlTable()
    {
        // Create a new DataTable.
        DataTable myDataTable = new DataTable("gpaTable");
        // Declare variables for DataColumn and DataRow objects.


        // Create new DataColumn, set DataType, ColumnName and add to DataTable.    
        DataColumn myDataColumn = new DataColumn();
        myDataColumn.DataType = Type.GetType("System.String");
        myDataColumn.ColumnName = "hrsToShow";
        myDataColumn.Unique = true;
        // Add the Column to the DataColumnCollection.
        myDataTable.Columns.Add(myDataColumn);




        // Instantiate the DataSet variable.
        DataSet myDataSet = new DataSet();
        // Add the new DataTable to the DataSet.
        myDataSet.Tables.Add(myDataTable);


        // Create three new DataRow objects and add them to the DataTable
        for (double i = 0.00; i <=9.50 ; i=i+0.50)
        {
            DataRow myDataRow = myDataTable.NewRow();
            myDataRow["hrsToShow"] = i.ToString("0.00");
            myDataTable.Rows.Add(myDataRow);
        }
        return myDataTable;
    }