Archive for the ASP.NET Tips Category

Format Cells When Exporting to Excel.

Posted in ASP.NET Tips with tags , , , , , on August 29, 2008 by nemosong

If you export gridview to excel, sometimes you will face format difference.

For example date field is 082008 on your gridview, but in excel file it becomes 82008. If the excel file is imported to another system or app, it could be a problem.

So here is a solution.

In the middle of your export function, write this:

// <– This block allows to change format cell as ‘text’. If not, some content changes its format.
// Ex: 082008 becomes 82008 in an excel file.
foreach (TableRow i in gridview1.Rows)
{
foreach (TableCell tc in i.Cells)
{
tc.Attributes.Add(“class”, “text”);
}
}
string style = @”<style> .text { mso-number-format:\@; } </style> “;
Response.Write(style);
// –>

And then you will see that the format is just same as gridview.!

Thanks to an article on http://forums.asp.net/p/1134560/1821199.aspx#1821199

Advertisements

Custom ‘Next’ button in Wizard control.

Posted in ASP.NET Tips with tags , , , on August 13, 2008 by nemosong

<asp:Wizard>

<StartNavigationTemplate> // <StepNavigationTemplate> also available.

<asp:Button />

</StartNavigationTemplate>

</asp:Wizard>

Enable/Disable ‘Next’ button in Wizard controls

Posted in ASP.NET Tips with tags , , , , on August 13, 2008 by nemosong

((Button)wizard1.FindControl(“StartNavigationTemplateContainerID”).FindControl(“btnNext”)).Enabled = true;

This is pretty much about it.. So simple.

Getting Values of Dynamically Created Controls.

Posted in ASP.NET Tips with tags on July 31, 2008 by nemosong

When you want to get a value of a dynamically created control, you need to create the control again while postback.

——————————————————-
for example:

protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
createDynamicDDL();
}

private void createDynamicDDL()
{
DropDownList ddl_1 = new DropDownList();
tc.add(ddl_1);  // TableCell(Let’s say tc already exist.)
tr.add(tc);
tbl.add(tr);
}

——————————————————-

Unless you don’t do this, NullReferenceException will be occurred.