Thursday, February 4, 2010

HOW TO DOWNLOAD EXCEL SHEET

protected void linkBtnDownLoad_Click(object sender, EventArgs e)
{
DownLoadExcel();
}

private void DownLoadExcel()//function for download excel sheet format.
{
try
{
//b4 download file make sure that file access is not denied ,so set file attribute IsReadonly to false.
string download_filename = Server.MapPath("../Reports") + "\\StudentRegistration.xls";
System.IO.FileInfo fileInfo = new System.IO.FileInfo(download_filename);
fileInfo.IsReadOnly = false;
FileStream fs;
fs = File.Open(Server.MapPath("../Reports") + "\\StudentRegistration.xls", FileMode.Open);
Byte[] bytBytes = new Byte[fs.Length];
fs.Read(bytBytes, 0, Convert.ToInt32(fs.Length));
fs.Close();
Response.AddHeader("Content-disposition", "attachment; filename=StudentRegistration.xls");
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytBytes);
Response.End();
}
catch (Exception ex)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, ex.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, ex.Source);
LCE.Configuration.ErrorLog("ManageUsers/ImportFromExcel.cs", errorMessage);
}
}

HOW TO HIDE AND SHOW DIV AT JAVASCRIPT

function ShowDiv()
{

document.getElementById('<%=div_reply_to_thread.ClientID %>').style.display='block';
document.getElementById('<%=td_btn_reply.ClientID %>').style.display='block';
document.getElementById('<%=td_btn_edit.ClientID %>').style.display='none';
}
function HideDiv()
{
document.getElementById('<%=div_reply_to_thread.ClientID %>').style.display='none';
}

HOW TO USE CUSTOMIZE COLUMN FIELD IN GRIDVIEW HOW TO USE HIDDEN FIELD

BorderColor="#999999" ForeColor="#FFFFFF" HeaderStyle-HorizontalAlign="Center"
OnRowDataBound="gvAllThreads_RowDataBound">

ItemStyle-ForeColor="#000000" ItemStyle-Width="40px" ItemStyle-HorizontalAlign="Center">

ItemStyle-Width="700px" ItemStyle-HorizontalAlign="Center">

< href="javascript:GetThreadID('<%# DataBinder.Eval(Container.DataItem,"ThreadID")%>')">
<%# DataBinder.Eval(Container.DataItem,"Subject")%>img




ItemStyle-ForeColor="#000000" ItemStyle-Width="150px" ItemStyle-HorizontalAlign="Center">

ItemStyle-ForeColor="#000000" ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Center">

ItemStyle-ForeColor="#000000" ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Center">

ItemStyle-Width="200px" ItemStyle-HorizontalAlign="Center">

< ID="lblLastPostDate" Text='<%#DataBinder.Eval(Container.DataItem,"LastPostedDate")%>'
runat="server">

< ID="lblPostedUserName" Text='<%#DataBinder.Eval(Container.DataItem,"FirstName")%>'
runat="server"> img1



ItemStyle-Width="75px" ItemStyle-HorizontalAlign="Center" Visible="false">

< href="javascript:Get_ThreadID('<%# DataBinder.Eval(Container.DataItem,"ThreadID")%>')">
img


ItemStyle-HorizontalAlign="Center" Visible="false">


onclick="javascript:SelectAll(this);" />


< id="chkAssign" runat='server' type="checkbox" value='<%#

DataBinder.Eval(Container.DataItem,"ThreadID")%>'
onclick="javascript:SelectedChange(this);" name="chkAssign" />





HOW TO fill installment dropdown list

ds1 = objcheck.CheckPaidInstallment();
if (ds1.Tables.Count > 0)
{
ddlInstallment.DataSource = ds1;
ddlInstallment.DataTextField = ds1.Tables[0].Columns["PaymentType"].ColumnName.ToString();
ddlInstallment.DataValueField = ds1.Tables[0].Columns["PaymentID"].ColumnName.ToString();
ddlInstallment.DataBind();
ddlInstallment.Items.Insert(0, "--Select--");
}

To show users photo, take users Image url from db. then assign image path of disk to ImageUrl.

string ImageUrlFromDB = dt.Rows[0]["ImageUrl"].ToString();
string UserImage = Session["rootPath"] + "/UserImages/" + ImageUrlFromDB.ToString().Trim();
Image1.ImageUrl = UserImage;
Image1.AlternateText = "img";

HOW TO SAVE USERS IMAGE IN DB: STORE ONLY PATH IN DB AND IMAGES IN FOLDER ON SERVER

protected void btnupload_Click(object sender, EventArgs e)
{
try
{
BLL_Users objimage = new BLL_Users();
objimage.UserID = Convert.ToInt16(Session["UserID"].ToString());
string filename = ImageUpload.FileName;//find the extension of the uploaded image.convert it into lower case.


//if following 2 lines(which remove readonly pro of the image) r make enable then images from client m/c will not

save to server
//System.IO.FileInfo fileInfo = new System.IO.FileInfo(ImageUpload.PostedFile.FileName);//first remove readonly

of any image from wher r u uploding
//fileInfo.IsReadOnly = false;

string fileName = Server.HtmlEncode(FileUpload1.FileName);
string ext= System.IO.Path.GetExtension(fileName);

if (ImageUpload.HasFile && ext == ".jpeg" || ext == ".jpg" || ext == ".bmp" || ext == ".png" || ext == ".gif")
{
ImagePath = Server.MapPath("../"); // find LMSBeta
string ImagePath1 = ImagePath + "UserImages"; // attach /LMSBeta/UserImages
objimage.ImageURL = Session["FirstName"].ToString() + Session["LastName"].ToString() + ext; //send

username+ext
objimage.UpdateUserImage();

ImageUpload.SaveAs(ImagePath1 + "\\" + Session["FirstName"] + Session["LastName"]+ ext); //if user register

then only save his image to disk with his username + ext.
Image1.ImageUrl = ImagePath1 + "\\" + Session["FirstName"] + Session["LastName"] + ext;
Response.Redirect("ViewProfile.aspx?action=viewprofile",false);
}
else
{
Session["imgErr"] = "Only .jpeg, .jpg, .bmp, .png, .gif file formats supported.";
Response.Redirect("ViewProfile.aspx?action=viewprofile",false);
}
}
catch(Exception ex)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, ex.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, ex.Source);
LCE.Configuration.ErrorLog("Include/UserRegistration.cs", errorMessage);
}
}

INSERT radiobutton value in db

objReg.Sex = RadioBtnSex.SelectedItem.Text;

select radiobutton value from db

if (Convert.ToString(dt.Rows[0]["Sex"]) == "M")
{
lbl_gender.Text = "Male";
}
else
{
lbl_gender.Text = "Female";
}