Thursday, September 08, 2011

Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible, possibly because the code is optimized.

Tuesday, February 01, 2011

Gridview RowEditing checkbox value

We know if we have manually binds the data then, we can access the checkbox or what ever the control by it's id.
as follows

CheckBox ck = (CheckBox)GridView1.Rows[e.NewEditIndex].Cells[8].FindControl("yourCheckBoxControl");



 



What if you auto bided the data to a gridview,



CheckBox ck = (CheckBox)GridView1.Rows[e.NewEditIndex].Cells[8].Controls[0];

Wednesday, January 26, 2011

DropDownList - Set selected value


The following code snippent shows how to set the selected item of a
DropdownList


 


DropDownList1.ClearSelection();
ListItem li = DropDownList1.Items.FindByValue("20");
DropDownList1.Items.FindByText(li.Text).Selected = true;


I have seen many beginners are struggling to set the selected value  dynamically,
Hope this is very helpful.

Sunday, January 16, 2011

The report you requested requires further information

This issue is a common one who starts working on Crystal Reports with Dataset (.Net)

loginerror

 

Ill show a sample code snippet where you can generate this issue.

                 ReportDocument report = new ReportDocument();    

BAgent bAgent = new BAgent();
DataSet dsStatus = new DataSet();
dsStatus = bAgent.GetStatus();

string reportPath = Server.MapPath("/Agent/Reports/GetStatusRpt.rpt");
report.Load(reportPath);

report.SetDataSource(dsStatus);// this is the line cause for this issue
CrystalReportViewer1.ReportSource = report;
CrystalReportViewer1.DataBind();
CrystalReportViewer1.RefreshReport();
 



Here is the solution, use the datset table instead of the dataset


 

                 ReportDocument report = new ReportDocument();    

BAgent bAgent = new BAgent();
DataSet dsStatus = new DataSet();
dsStatus = bAgent.GetStatus();

string reportPath = Server.MapPath("/Agent/Reports/GetStatusRpt.rpt");
report.Load(reportPath);
                 report.SetDataSource(dsStatus.Tables[0]); 
CrystalReportViewer1.ReportSource = report;
CrystalReportViewer1.DataBind();
CrystalReportViewer1.RefreshReport();

 


Hope you got rid from this issue. Enjoy coding.

Thursday, January 13, 2011

GridView Hidden Column Data Access

Again I faced an issue, as usual before .net version 2.0 I set a column's visibility property of a gridview to false.
If you are a developer by now you know why I did that. I know you guessed it. I just wanted to use that column's value
in one of my calculations, and didn't want to show it to the user.

Grid is working fine it hides the column I wanted to hide, I am happy!., Suddenly I realized that I don't get the value from
the hidden (visibility= false) column's cell value in the following method.

 

 protected void grd_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = grd.SelectedRow;
string aValue = row.Cells[8].Text; //this is the column I set false visibility
}


I was looking my coding deeply I am sure this is correct 100%, then what has gone wrong?

With 2.0 and above versions on .Net when you set a column of a gridview to visibility false


it doesn't  bind the data to this hidden column. You must be really disappointed hearing this


news, even I did. Wait you don't have to worry so long.



Don't set your column's property visibility to false in the design view. If you do so it will

call before the databind. When there is no column databing is not take place and ignores this hidden column.


Obvious we  don't get data (you are lucky only you didn't get the data, worse case this might throw an error)



Trick to overcome this issue,



RowCreated event of a GridView takes place after the data binding, so we can do something like following

code snippet.



 protected void grd_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[8].Visible = false;
}



This hides the column, still you can access the cell value,



 protected void grd_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = grd.SelectedRow;
string aValue = row.Cells[8].Text; //I get the cell value, I am happy!
}


 


Enjoy working on Gridview control,

My Achievements

Member of

Blog Archive

Followers