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();
}
}

STORED PROCEDURE

Following steps may helpfull for you to write the stored procedure:
  Q : Need a stored procedure which will help you to insert data in a database table.
( here database name is "anil"  and  table name is "emp". which consists the fields  eno,ename)

stored procedure formate:
USE  [database name]
CREATE PROCEDURE  [procedurename]
@fieldname1 datatype= _ ,
AS
BEGAN
"query"
END

Example 1:
Open query analyser in the sql server and write the following
USE  anil
CREATE PROCEDURE STP_EMP
@ENO
varbinary(MAX) = null,
@ENAME varchar(50) = null
 AS
BEGIN
 INSERT INTO emp(eno,ename) VALUES(@ENO,@ENAME)
END
Exicute the above procedure you will get the "Command exicuted Successfully msg".

Now Open the Default.aspx.cs page and write the following code:

SqlConnection con = new SqlConnection("Data Source=ADMIN-PC;Initial Catalog=anil;Integrated Security=True");

con.Open();
SqlCommand cmd = new SqlCommand("STP_EMP",con);// Call the procedure Name.
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ENO",SqlDbType.Int).Value = TextBox1.Text;(or) 1;
cmd.Parameters.Add("@ENAME", SqlDbType.VarChar).Value = TextBox2.Text; (or )name ;
cmd.ExecuteNonQuery();
con.Close();

Tuesday, January 4, 2011

Redirecting to another page with some command argument

<asp:link button id="lnk1" runat="server"   NavigateUrl='<%# "page2.aspx?id=" + Eval("ID") %>'>More.....</link button>