Monday, January 2, 2012

How to increase the file size in upload the attachment in ASP.NET


<configuration>
  <system.web>
//  --------  <httpRuntime maxRequestLength="xxx" />---------//
 <httpRuntime maxRequestLength="104856" executionTimeout="43200" requestValidationMode="4.0" />
  </system.web>
</configuration>

Friday, December 30, 2011

Show the msg before deleting data from the grid view in asp.net


i wrote the code in source window,

<asp:button  id="btn1" OnClientClick="javascript:return confirm('Are you sure you want to Delete this Record!');"   ></asp:button>

(or)

function confirm_Delete() {
                var msg = confirm("Are you sure you want to Delete this Record!");

                if (msg == true) {
                    alert("Record Deleted");
                    return true;
                }
                else {
                    return false;
                }
            }

Thursday, December 29, 2011

How to get the ID from db using Datakeys in ASP.NET



source page:
========
<gridview   ........ DataKeyNames="IdeaID"   ></gridview>
Code Behind:
=========

 protected void grdMyIdea_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
             
                if (e.CommandName == "Edit")
                {
                    Response.Redirect("Idea.aspx?Ideaid=" +e.CommandArgument );
                }
                if(e.CommandName == "Delete")
                {
                    int intValue = 0;
                    DataAccessLayer _objDAL = new DataAccessLayer();
                    GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
                    int IdeaID = Convert.ToInt32(((System.Web.UI.WebControls.GridView)   (sender)).DataKeys[row.RowIndex].Value);
                    SqlParameter[] _sqlparam = new SqlParameter[1];
                    _sqlparam[0] = new SqlParameter("@Ideaid", IdeaID);
                    intValue = _objDAL.Manipulation("THRSP_MyideaDelete", _sqlparam);
                    GetdataMyidea();
                   
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Thursday, December 22, 2011

Send Email Functionality using ASP.NET with c sharp


Web.config file:
===========
<configuration>
  <appSettings>
    <add key="Email" value="chitharan89@gmail.com"/>
  </appSettings>
  <system.net>
    <mailSettings>
      <smtp >
        <network host="127.0.0.1" port="25" userName ="chitharan89@gmail.com" password ="9715929121" />
      </smtp>
    </mailSettings>
  </system.net>
<connectionStrings>
<add name="connection" connectionString="Data Source=SPTEST;database=db1;Integrated Security=True;  "/>
</connectionStrings>
</configuration>

protected void imgBtnshare_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string FromEmail = ConfigurationManager.AppSettings["Email"].ToString();
                string ToEmail = "chitharan89@gmail.com";
                MailMessage Message = new MailMessage(FromEmail, ToEmail);
                Message.Subject = "To Share the Idea to Friends";
                Message.Body = "The main Purpose sharing ideas to friend and get reply ";                              
                Message.IsBodyHtml = true;
                SmtpClient SMTP = new SmtpClient();
                SMTP.Send(Message);
               
               
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);

            }

        }

Fetch the gridview data and display next page textboxes throw Query string using ASP.NET


 protected void grdMyIdea_RowCommand(object sender, GridViewCommandEventArgs e)
        { 
            try
            {
              
                if (e.CommandName == "Edit")
                {
                    Response.Redirect("sampleidea.aspx?Ideaid=" +e.CommandArgument );
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

ANOTHER PAGE: Ideaid is primarykey is also used in this table..fetch by another table Title and Description how? 

 protected void Page_Load(object sender, EventArgs e)
 {
           int Ideaid = 0;
           Ideaid = Convert.ToInt32(Request.QueryString["Ideaid"].ToString());
          
            if (!IsPostBack)
            {
                Getdata();
            }

public void Getdata()
        {
            SqlConnection con = new SqlConnection(connection);
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("select Title,Description from Idea where Ideaid='" + Request.QueryString["Ideaid"].ToString() + "'", con);
            con.Close();
            DataSet ds = new DataSet();
            da.Fill(ds);
            TextBox1.Text = ds.Tables[0].Rows[0]["Title"].ToString();
            TextBox2.Text = ds.Tables[0].Rows[0]["Description"].ToString();
           
           
        }
 

Wednesday, December 21, 2011

Show msg onclick client side only using source file code.

OnClientClick="return confirm('Edit the file permanently ?');"

Grid view Serial No count will be generated automatically using this Code


protected void grid1_RowDataBound(object sender, gridviewRowDataBound e)
{
 if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblno = (Label)e.Row.FindControl("lblSerialNo");
                lblno.Text = ((grdMyIdea.PageIndex * grdMyIdea.PageSize) + e.Row.RowIndex + 1).ToString();
            }
}