Saturday, July 14, 2012

join Name Value Collection Keys and values asp dot net

NameValueCollection nvc = new NameValueCollection(); 
//Fill collection
string sql=""; 

sql = "INSERT INTO [TABLENAME]";

//Join all keys with ],[ as seperator
sql += string.Format(" ([{0}])"string.Join("],[", nvc.AllKeys));
//Join all values with ',' as seperator 
sql += string.Format(" VALUES('{0}')"string.Join("','", nvc.AllKeys.Select(key => nvc[key]))); 
 
 

Converting byte[] to string in asp dot net c#

string str = System.Text.Encoding.UTF8.GetString( byte[] arr );

Monday, July 9, 2012

HTML5 equivalent of cellpadding, cellspacing, valign, and align?

/*cellpadding*/
thtd { padding0; }
 
/* cellspacing */
table { border-collapse:separateborder-spacing0; }
 
/* valign */
thtd { vertical-aligntop|middle|bottom; }
 
/* align (center)
   width of table must be less than the parent container */
table { margin0 auto; }

Saturday, July 7, 2012

How to hide the Group Tree of a Crystal Report


cViewer.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;

Multiple Eval Fields in Gridview ItemTemplate


<%# String.Format("{0} - {1}", Eval("Name1"), Eval("Name2")) %>

JavaScript URL encode


encodeURIComponent(str);

jQuery get specific option tag text


$("#list option:selected").text();

Adding roles to the 'CreateUserWizard'


Add this to create user table
<tr>
<td align="right">
 <asp:Label ID="RolesLabel" runat="server" Text="Roles" AssociatedControlID="DropDownListRoles"></asp:Label>
 </td>
 <td>
 <asp:DropDownList ID="DropDownListRoles" runat="server">
 </asp:DropDownList>
 </td>
 </tr>

And then this to code
protected void Page_Load(object sender, EventArgs e)
    {
        DropDownList roleDropDownList = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListRoles");
        roleDropDownList.DataSource = Roles.GetAllRoles();
        roleDropDownList.DataBind();
    }
 
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        DropDownList roleDropDownList = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListRoles");
        Roles.AddUserToRole(CreateUserWizard1.UserName, roleDropDownList.SelectedValue);
    }