Wednesday, January 8, 2014

Freelance Work: Website Design


Hi All,

I need a website that needs to be deployed on linux environment. The theme of the website would be freelancing.
I require a very basic site that has options which a common freelancer site has. The only thing needed as for now is the design of the site.

Please post your interest for the same as comments or use the Contact CodersCafe Form. 

Include the following in your details:

Your Name:
Your Email Address:
Your Contact Number:
Technology You Would Be Using:
Duration To Complete The Design [This excludes project analysis]: 

Note:

Freshers can also apply for the same.
A final discussion with the designer / developer would let the work assigned and all payment discussions would be done thereafter.

Regards
Coders-Cafe

Saturday, December 21, 2013

Asp.Net databound field shows   character when null or empty.

When working with gridview in Asp.Net one of the most common behaviour that is often seen is   in bound Field Columns. This is the case when datasouce is having empty string which is binded to the gridview.

Whenever in the datasource which is being binded to the gridview has empty string (""), it is mostly retrieved as  .

To address this, or if you need some default value instead of  , the BoundField class provided "NullDisplayText" property which can be used.

"NullDisplayText"  Gets or sets the caption displayed for a field when the field's value is null. [as per msdn],

Even if the field value is empty string ("") and if you set "NullDisplayText" as " ", this would no more give you   as empty string ("") is rendered as  .

Therefore you do not need to put any additional checks in the code to handle  .

[GridView code .aspx page]
 <asp:GridView ID="grdTestGrid" runat="server" AutoGenerateColumns="false" onrowcommand="grdTestGrid_RowCommand">  
     <Columns>  
       <asp:BoundField DataField="name" HeaderText="Name" NullDisplayText=" "/>  
       <asp:BoundField DataField="email" HeaderText="Email"/>  
       <asp:TemplateField HeaderText="GetValue">  
         <ItemTemplate>  
           <asp:Button ID="btnGetValue" runat="server" Text="Get Value" CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' UseSubmitBehavior="False" />  
         </ItemTemplate>  
       </asp:TemplateField>  
     </Columns>  
 </asp:GridView>  

Explanation:

The above code for gridview has two BoundField's name and email. In one of the field which is "name" we are using NullDisplayText property and setting its value to " ". Due to this if the binded value from source comes as null or an empty string ("") it would give you " " value instead of &nbsp; and hence would not require any special handling on code-behind for &nbsp;.

The second field value on retrieval would display &nbsp; if the binding value from source comes as null or an empty string ("").


[GridView RowCommand code .aspx.cs file]
1:  using System;  
2:  using System.Collections.Generic;  
3:  using System.Linq;  
4:  using System.Web;  
5:  using System.Web.UI;  
6:  using System.Web.UI.WebControls;  
7:  using System.Data;  
8:  public partial class _Default : System.Web.UI.Page  
9:  {  
10:    DataTable dataTable;  
11:    DataRow dataRow;  
12:    protected void Page_Load(object sender, EventArgs e)  
13:    {  
14:      dataTable = new DataTable();  
15:      dataTable.Columns.Add("name", typeof(string));  
16:      dataTable.Columns.Add("email", typeof(string));  

17:      dataRow = dataTable.NewRow();  
18:      dataRow["name"] = "Vivek Joshi";  
19:      dataRow["email"] = "testemail@email.com";  
20:      dataTable.Rows.Add(dataRow);  

21:      dataRow = dataTable.NewRow();  
22:      dataRow["name"] = "";  
23:      dataRow["email"] = "";  
24:      dataTable.Rows.Add(dataRow);  

25:      grdTestGrid.DataSource = dataTable;  
26:      grdTestGrid.DataBind();  
27:    }  

28:    protected void grdTestGrid_RowCommand(object sender, GridViewCommandEventArgs e)  
29:    {  
30:      int rowIndex = int.Parse(e.CommandArgument.ToString());  
31:      string strName = grdTestGrid.Rows[rowIndex].Cells[0].Text;  
32:      string strEmail = grdTestGrid.Rows[rowIndex].Cells[1].Text;  
33:    }  
34:  }  

Explanation:

Page Load:
In the code-behind code above, we have created a datasource which is having two rows of which one row has values and the other does not have anything. The second row for now has been assigned as empty string (""). null can also be used as well for testing.

Grid RowCommand:
In this event we are retrieving the value of cells for which the event is raised. For first row all would be well as we neither have null nor an empty string ("") for both cells.

For the second row both the cells have empty string (""). As we are using The NullDisplayText=" " for BoundField "name" we would get " " on retrieving the value, but for the BoundField email we would get &nbsp;.

This is how we can avoid &nbsp;. Also this is just an other way for handling &nbsp;.

If you have any querries or sugesstions, please leave a comment.

Regards
Vivek Joshi

Friday, November 15, 2013

Access Server-Side Variables, Property In External JavaScript: C#



Accessing Server-Side Variables, Property In External  JavaScript: C#

At times there may be a requirement to access the server-side variables in External JavaScript. To achieve the same we can follow the following:

The language used for server-side variable is c#.

For a server-side variable to be accessed in External JavaScript, the variable declared must be public.

Server-Side C# Code:

 public string strTempVar = "some value";  

JavaScript Code:

 <script type="text/javascript" language="javascript">  
   var strTempVarValue = "<%= strTempVar%>";  
 </script>  
 <%-- Add the external script reference where server side variable value needs to be accessed--%>  
 <script src="path of the externalJavaScript.js" type="text/javascript"></script>  

This is how we can access a server-side variable in external JavaScript File. The variable strTempVarValue would now be accessible in external JavaScript.

The same can be used for accessing property as well.

Regards
Vivek Joshi