Monday, May 23, 2011

How to add the dynamic controls [ java script ]


<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT language="javascript">
function add(type) {

    //Create an input type dynamically.
    var element = document.createElement("input");

    //Assign different attributes to the element.
    element.setAttribute("type", type);
    element.setAttribute("value", type);
    element.setAttribute("name", type);

    var foo = document.getElementById("fooBar");

    //Append the element in page (in span).
    foo.appendChild(element);

}
</SCRIPT>
</HEAD>
<BODY>
<FORM>

Select the element and click Add to add it in form.
<BR/>
<SELECT name="element">
    <OPTION value="button">Button</OPTION>
    <OPTION value="text">Textbox</OPTION>
    <OPTION value="radio">Radio</OPTION>
</SELECT>

<INPUT type="button" value="Add" onclick="add(document.forms[0].element.value)"/>

<span id="fooBar">&nbsp;</span>

</FORM>
</BODY>
</HTML>


Sunday, May 22, 2011

simple File Upload

string filename = FileUpload1.FileName;
        FileUpload1.SaveAs(Server.MapPath("~/css/") + filename);


FileUpload1 is the  ID of file upload control.

~/css   is the folder to which we are up

Monday, March 21, 2011

  if (ds.Tables[0].Rows.Count > 0)
                    {
                        Session["Uid"] = ds.Tables[0].Rows[0]["User_Id"].ToString();
                

Wednesday, March 2, 2011

One click DOWN LOAD DOCUMENT

  string textFile = string.Format("{0}.txt", DateTime.Now.ToString("MM-dd-yyyy_HH-mm-ss"));
 System.IO.StreamWriter streamWriter = File.CreateText(string.Format(@"{0}{1}", "D:\\", textFile));
  streamWriter.WriteLine(Textbox.Text); //( pass the string from which you want get input to write in the doc.)
            streamWriter.Close();
above  works for local


For server :

           textFile = string.Format("{0}.txt", DateTime.Now.ToString("MM-dd-yyyy_HH-mm-ss"));
           // string textFile = string.Format("{0}.txt", DateTime.Now.ToString("MM-dd-yyyy"));
             string kk = string.Format(@"{0}{1}", Server.MapPath("Download/"), textFile).ToString();
            System.IO.StreamWriter streamWriter = File.CreateText(string.Format(@"{0}{1}", Server.MapPath("Download/"), textFile));
            streamWriter.WriteLine(download_htmlcode.ToString());
            streamWriter.Close();

            HttpContext.Current.Response.ContentType = "application/octet-stream";
            //HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(kk));
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename="+"Yourdesign");
        
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.WriteFile(kk);
            HttpContext.Current.Response.End();

Thursday, February 24, 2011

how to include multiple double coats[ " "] in the string

string s="select * from emp where emp(\"temp1\")";

o/p  :            select * from emp where emp("temp1")

string k= "<input name=\"item_name_" + k.ToString() + "\" type=\"hidden\" value=\"" +k.ToString() + "\"> ";        
                 <input name="item_name_anil" type="hidden" value="anil">

Wednesday, February 9, 2011

Display Row total in footer of gried

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White"
        BorderColor="#336699" BorderStyle="Solid" BorderWidth="1px" CellPadding="2" Font-Names="Verdana"
        ShowFooter="true" Font-Size="10pt" Width="50%"  GridLines="Horizontal"
        OnRowDataBound="GridView1_RowDataBound">
        <Columns>
             <asp:TemplateField HeaderText="Date">
                <ItemTemplate>
                    <asp:Label ID="lblPrice" runat="server" Text='<%# Eval("date")%>' />
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Label ID="lblTotalPrice" runat="server" />
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="salary">
                <ItemTemplate>
                    <asp:Label ID="lblUnitsInStock" runat="server" Text='<%# Eval("sal") %>' />
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Label ID="lblTotalUnitsInStock" runat="server" />
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </FooterTemplate>
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#336699" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
      
        <HeaderStyle BackColor="#336699" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
    </asp:GridView>




 private void BindData()
    {
        SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=anil;Integrated Security=True");

        string query = "SELECT * FROM anil";

        SqlDataAdapter da = new SqlDataAdapter(query, con);
        DataTable table = new DataTable();

        da.Fill(table);

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



    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=anil;Integrated Security=True");

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            tsals += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "sal"));

        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[1].Text = String.Format("{0:c}", tsals);
        }
    }

Friday, January 28, 2011

Add controls dynamically

 Explain how to add controls dynamically to the form using C#.NET.The following code can be called on some event like page load or onload of some image or even a user action like onclick
protected void add_button(Button button)
{
try
{
panel1.Controls.Add(button); // Add the control to the container on a page
}
catch (Exception ex)
{
label1.Text += ex.Message.ToString();
}
}