Saturday, March 26, 2011

Literal

I found out something today the Literal control that we use so much with dynamic displays (at least I do) does not support cssClass.
I had a literal control and all I did was added class="msg" ...

<asp:Literal ID="litContactMsg" runat="server"></asp:Literal>

I tried this

<asp:Literal ID="litContactMsg" runat="server" class="msg"></asp:Literal>

and I got the error creating control message
and then i read http://msdn.microsoft.com/en-us/library/system.web.ui.literalcontrol.aspx
and it was some straight thinking that got me to the fact that its a container since it has the childcontrol property
well so what if it is....I mean hey ... there are others with children.... and then W3C showed up
see this..

http://www.w3schools.com/ASPNET/control_literal.asp




my God! its simple things that bowl you over.

Flip video

When you capture video from s phone, its not horizontal after you transfer it to the PC, I tried downloading softwares to flip videos but all the time, it was right there, in VLC player
I asked Mr.Google and I found this
 http://www.howtogeek.com/howto/14751/rotate-a-video-90-degrees-with-vlc-or-windows-live-movie-maker/

Friday, March 25, 2011

NamingContainer

This article here http://aspadvice.com/blogs/joteke/archive/2007/02/25/Understanding-the-naming-container-hierarchy-of-ASP.NET-databound-controls.aspx decribes the NamingContainer property.

When using a TemplateField in a GridView i.e. when you use... a checkbox to update the database OnCheckChanged of the checkbox


<asp:TemplateField HeaderText="active">
            <ItemTemplate>
            <asp:CheckBox ID=chkEmpActive AutoPostBack=true Checked='<%#Eval("active")%>' runat=server OnCheckedChanged=chkEmpActive_CheckedChanged />
            <asp:HiddenField ID=hidActive runat=server Value='<%#Eval("emp_id")%>' />
            </ItemTemplate>
 </asp:TemplateField>

its easier to have a hidden field with it;helps with the update and to find it,  the NamingContainer of the CheckBox can be used to get to the hiddenfield

when you do


protected void checkbox1_oncheckchange(object sender, EventArgs e)
{
    CheckBoc chk =(CheckBox)sender;
    GridViewRow row = (GridViewRow)chk.NaminConatiner;
    HiddenField hidEmp = (HiddenField)row.FindControl("hidActive");
    empNo = HiddenField.Value; // where empNo is a global var
}

you can use the empNo variable in JavaScript

<script>
var empno = <%=empNo%>

//and use it some calculations

</script>

I used the empNo to call an ASP page using the httpXml object and do some database operations





Monday, March 21, 2011

run query on DataSet


I had a stored procedure that returned indistinct data... like it returned
P1
CompanyProductTotal
C1P1T1
C1P2T2
C2P3T3
C2P4P4

I wanted a report like

Company 1
P1T1
P2T2
Company 1
P3T3
P4P4

instead of running a query on the database again and again, I wanted to do it using the table returned by the DataSet

using a datalist that has a grid in its template colum see http://www.aspdotnetcodes.com/GridView_Inside_DataList.aspx

Using the above technique ,
when binding the list

private void bindList()
        {
            string prevCo = "";
            DataTable table = new DataTable();
            table.Columns.Add("CompanyName");
            //get the companies
            //if 'Dictinct' could be run on the dataset, it would be cool
            foreach (DataRow row in mainDs.Tables[0].Rows)
            {
                if (prevCo == row["CompanyName"].ToString())
                {
                    //do nothin'
                }
                else
                {
                    DataRow dr = table.NewRow();
                    dr["CompanyName"] = row["CompanyName"].ToString();
                    table.Rows.Add(dr);
                }
                prevCo = row["CompanyName"].ToString();
            }
            table.AcceptChanges();

            DataList1.DataSource = table;
            DataList1.DataBind();
        }

and bind the grid on DataList's itemdatabound method

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            GridView GridView1 = (GridView)e.Item.FindControl("GridView1");
            BindGrid(GridView1, DataList1.DataKeys[e.Item.ItemIndex].ToString());
        }

where datakeys[] is set to the company name.
<asp:DataList id=DataList1 runat=server DataKeyField="CompanyName" OnItemDataBound="DataList1_ItemDataBound" >

and

private void BindGrid(GridView GridView, string CompanyName)
        {

            DataTable table = new DataTable();
            table.Columns.Add("Sno");
            table.Columns.Add("ProductName");
            table.Columns.Add("Total");
            int counter = 1;
            foreach (DataRow row in mainDs.Tables[0].Rows)
            {
                if (row["CompanyName"].ToString() == CompanyName)
                {
                    DataRow dr1 = table.NewRow();
                    dr1["Sno"] = counter.ToString();
                    dr1["ProductName"] = row[0].ToString();
                    dr1["Total"] = row[2].ToString();
                    table.Rows.Add(dr1);
                }
                counter++;
            }
            table.AcceptChanges();

            GridView.DataSource = table;
            GridView.DataBind();
        }

Im sure this can be done better with Linq.
this seemed pretty easy in this scenario.

and there is also http://www.queryadataset.com/

UPDATE: you can download the source of the test site I created, and please make sure you have the nothwind database of the SQL server sample databases.
download : http://saudkhan.net/work/Web/dataListTest.rar

Sunday, March 13, 2011

CheckBox onmouseover and Classic ASP update DB

Im working on an old application in ASP 3.0. There is page that displays a grid (not GridView but a few Response.Writes with <TR><TD>...) A CheckBox (<input type... not <asp:...) is displayed on one of the colums that need have an updated database value. Thank heavens, the database contained a bit field and a checked or unchecked value is displayed depending on the database query results.In ASP (VB) .
The thing is I had to display a message layer (div) near (zindex=2) the cursor when the user moved the cursor near the CheckBox.
The CheckBox is contained in the layer. And with proper width you could display the message layer starting from anywhere until the containing layer goes.
One other thing is that a different message is to be displayed it the user is about to check or uncheck it.
This can be done by using the recordset retured value for the bit field that we are checking and name the div layer (container div) and checkbox with a leading 1 or 0 like this
<%
if CStr((rs("active").Value)) = CStr("True")) Then
Response.Write "<div id=div1 align=center style='width:25Px;height:30Px;background-color:Aqua' onmouseover=ShowContent('msg',this);  onmouseout=HideContent('msg'); ><input type=checkbox id=chk1 onmouseover=ShowContent('msg',this); onmouseout=HideContent('msg'); checked=checked/></div>"
Else

Response.Write "<div id=div0 align=center style='width:25Px;height:30Px;background-color:Aqua' onmouseover=ShowContent('msg',this);  onmouseout=HideContent('msg'); ><input type=checkbox id=chk0 onmouseover=ShowContent('msg',this); onmouseout=HideContent('msg');/></div>"
End if
%>

Then in JavaScript 
<script>
 var Xpos = 0; 
 var Ypos = 0;
 var cX = 0;
 var cY = 0;

//event to get mouse positions
 function GetMouse(e) {
    cX = e.pageX; cY = e.pageY;
 }

 function GetMouseForAll(e) {
     cX = event.clientX; cY = event.clientY;
 }
 if (document.all) {
     document.onmousemove = GetMouseForAll; 
 }
 else {
     document.onmousemove = GetMouse;
 }

 function ShowContent(d, chk) {
        if(d.length < 1) { return; } //error check if there is no div...that wont happen
        var dd = document.getElementById(d);
        AssignPosition(dd); //
        dd.style.display = "block";
        if(chk.id.indexOf("1")<=0)
        dd.innerHTML = 'Uncheck here to make user Active';
        else
        dd.innerHTML = 'Check here to make use InActive';
}
function HideContent(d) {
        if (d.length < 1) { return; } //error check if there is no div...that wont happen
        document.getElementById(d).style.display = "none";
}


function AssignPosition(d) {
//the self.pageXoffset willwork in firefox and chrome but for IE 
//documentelement.scrollLeft or right Im not so sure so please look it up
   Xpos = self.pageXOffset;
           Ypos = self.pageYOffset;
         
           d.style.left = (cX-180) + "px";
           d.style.top = (cY-100) + "px";
}

</script>


Add a div in the html page 

<div  id="msg" 
   style="display:none; position:absolute; background-color: purple; color=white; padding: 5px;">
   Activate/De-Activate user<br />for timesheet approval process
</div>

after this each time the chebox in checked we have to update the database
I simply did a form.submit()
but using httpXML stuff of ASP Classic is better
here is an awesome example that even demonstrates usage with google API's
here is the example learning example that I like

At the end of the day, thank god for ASP.NET 

Thursday, March 10, 2011

Hello world on monodroid

I started with monodroid recently . When you start you notice the programming structure is very different.
Droid stuff starts off with a Activity class. this is where the application starts, its like our very own program.cs.
Lets begin at the beginning
in visual studio 2010, the android template see installation instructions here : http://mono-android.net/Installation
visual studio writes a start up application for you. once you  run it http://mono-android.net/Tutorials/Hello_World
the emulator starts off and the program is deployed to the emulator.
I directly ran the code VS wrote, and it did come up with a decent looking program that had a button that counted the number of clicks.
The code in the class itself is not used for the UI, there is a Xaml file that is used for this purpose.
I will work on creating some UI and update  soon hopefully.