Monday, June 30, 2008

C# ? :

(cond ? true : false)

example: Session["IsManager"] = ( IsManager ? "T" : "F" );

inserting texbox inside of the gridview

This took me awhile.. Here is my solution.

Here is an idea...
1. Create gridview
2. Create blank templatefield
3. Bind gridview
4. Grab hold of the holder like page, from, placeholder that has the gridview
5. Find "GridView" control(s).
6. Grab hold of rows
7. Insert by row.cells[i].controls.add(your control);

For some reason i couldn't add itemtemplate or edittemplate like how I could add boundfield inside of the gridview.
instead, I created an empty TemplateField

GridView myGrid = new GridView();
// add other GridView Properties and events...

TemplateField tf1 = new TemplateField();
tf1.HeaderText = "Header Text";
tf1.HeaderStyle.Width = Unit.Pixel(ScoreColunmWidth);
tf1.ItemStyle.HorizontalAlign = HorizontalAlign.Center;

myGrid.Columns.Add(tf1);


Then you need to databind the gridview. then you have a working GridView.

The code below is O = n^2... there might be better algorithms to do this. Maybe add textbox during mygrid creation. that way, there is no loop... but this is decent. Eefficiency gain by 0=1 versus n^2 is very small in this case.
Corn Chowders!

private void addTextBoxforScoreColumn()
{
var Controls = PlaceHolder1.Controls;

int rowCount = 0;

// this is O = n^2
foreach (var x in Controls)
{
if (x.ToString().Contains("GridView"))
{
GridView gridview = (GridView)x;

foreach (GridViewRow row in gridview.Rows)
{
TextBox textbox = new TextBox();
textbox.Width = 50;
textbox.ID = "x";
row.Cells[0].Controls.Add(textbox);
}
}
}
}

Sunday, June 29, 2008

Null return from iqueryable

When you do
var query = from p in db.xxx
select p;

Let's say there are two fields
FirstName and LastName

From above Query

Query.FirstName and Query.LastName are returned.

Let's say FirstName is an empty field but not Null.
LastName is Null;

FirstName is equal to both Null and string.empty.
LastName is equal to string.empty.

thus either null or string.empty can be == to string.empty

so... you can do

if ( query.FirstName == string.empty) { }
if ( query.LastName == string.empty) { }

.net calendar control

This is rather simple but... I apparently I didn't know.

if you want to set your calendar control to today's date, you can....

Calendar1.SelectedDate = DateTime.Today;

I would think Calendar control would have something like
Calendar.SetToToday() method..

ooops, it doesn't..

Thursday, June 26, 2008

Reading Lawson 8 data from asp.net 3.5

[ C# ][ ASP.NET ][ .NET Framework 3.5 ][ Lawson 8 ]

String LAWSON_UID = "xxxxx";
String LAWSON_PASSWORD = "xxxxxx";
String URL = "http://webhost/cgi-lawson/dme.exe?.......&OUT=XML";

XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = new NetworkCredential(LAWSON_UID, LAWSON_PASSWORD);
XmlTextReader oXML = new XmlTextReader(URL);

oXML.XmlResolver = resolver;

XmlDocument doc = new XmlDocument();
doc.Load(oXML);

I have tried httpwebrequest/httpwebresponse object... but for some reason they were problematic.
btw, if you have version 9, reference "Doc for Developers: ISO Application Program Interfaces" from support.lawson.com

I am not a lawson developer or admin. However, I am having to use the data.

this solution is simple but it took me while for me to get it...

anyway, hope this helps..

Wednesday, June 11, 2008

Asp.net and CGI Variable...

http://www.stonejunction.com/articles/.net/asp.net/ServerVariables.htm