Friday, October 29, 2010

Which Templated Checkboxes in an Infragistics Webdatagrid Column are Checked

This is the codebehind I use to see which templated checkboxes in an infragistics webdatagrid column are checked.
 
private void TakeActionOnSelectedCustomers ()
{
if (igWdgCustomers.Rows.Count != 0)
{
foreach (GridRecord row in igWdgCustomers.Rows)
{
CheckBox theCB = (CheckBox)row.Items[0].FindControl("cbSelect");
if ( theCB!= null && theCB.Checked)
// check for null because footer row doesn’t have cb

{
// take action
}
}
}
}

This is the column being checked.

<ig:TemplateDataField Key="cbSelect" width="30px">
<Header Text=" " />
<ItemTemplate>
<asp:CheckBox ID="cbSelect" runat="server" />
</ItemTemplate>
</ig:TemplateDataField>


In this case the checkbox is not databound, but it could be.

I have not found a way to use the CRUD feature of the datasource that the WebDataGrid uses to update the db value of a boolean represented by a databound checkbox.

Friday, August 27, 2010

DateTime.ParseExact

So after never having had CultureInfo.CurrentCulture on my radar, I ended up using it twice this week.

For the first use, see my previous post on ToUpperInvariant().

Today, I ran into a problem where I tried DateTime.Parse on a string which I had generated in a gridview using:

<asp:BoundField DataField="DateStarted"
  DataFormatString="{0:ddd MMM d hh:mmtt}" />
The compiler couldn't parse it.

I ended up having to decode it using the following:

DateTime dateCreated =DateTime.ParseExact(sdateCreated,
  "ddd MMM d hh:mmtt", CultureInfo.InvariantCulture);

ToUpperInvariant()

Whoa! Jon Skeet answered a question of mine on StackOverflow this week! I am honored.

The question was:

In C# what is the difference between ToUpper() and ToUpperInvariant()?

And the answer was, in a nutshell, "Unless you are programming in Turkish, no difference."

What brought me to ask that question started with a need to always reformat user input for first and last name with Initial Letter Case: first letter capitalized, rest lower case. (I know, I know, this is not all last names follow this convention, but hey, I didn't define the user requirements.) (In word I use Shift-F3 all the time.)

So I went looking in intellisense for a string method called InitialLetterCase(). After all, there are string methods ToUpper() and ToLower().

There was no InitialLetterCase() method, but I found ToUpperInvariant(). What did that do? I did a google search but the first few hits didn't seem to answer the question.

So thank you, Jon Skeet and StackOverflow, for the answer.

FYI, the solution to my request is a simple

tbFirstName.Text =
CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tbFirstName.Text); :

Wednesday, July 7, 2010

RegisterStartupScript vs Response.Write

Even though putting windows popup alerts into your UI can be bad design, annoying to your users, etc, sometimes it's just what you need to get the job done. I feel it's ok to use an occasional windows alert, as long as you don't abuse them.

If you are also using Ajax, you have a choice of 2 ways to program that alert from the code behind: Response.Write or ScriptManager.RegisterStartupScript.

The difference is that Response.Write will popup an alert box before the page loads, ie on a white background, and ScriptManager.RegisterStartupScript will pop it up after the page has loaded, so the page is visible behind the popup.

I prefer using ScriptManager.RegisterStartupScript, but maybe I just haven't come across an application where Response.Write would be better.

In any case, the following is the code to use for each case:

Response.Write("<script language='javascript'> 
      alert('This pops up on a blank page
     (ie before the page loads) using response.write');</SCRIPT> "
);
ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, 
  "alert('This pops up after the page loads,
     using ScriptManager.RegisterStartupScript');"
, true);
 


I have also popped up an alert on pageload by using the following in the html < body> tag of the page:

<body onLoad="alert('Update. \r\n \r\n Thank you for your interest,
\r\n however, \r\n we are not taking any new orders at this time.')"
>
The \r\n causes a line break.

Tuesday, June 29, 2010

Because I always forget proc names ...

protected void Page_PreInit(object sender, EventArgs e)
{
string msg = "Fires 1";
}

protected void Page_Init(object sender, EventArgs e)
{
string msg = "Fires 2";
}


protected void Page_Load(object sender, EventArgs e)
{
string msg = "Fires 3";
}

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string msg = "Fires last";
}

Thursday, June 17, 2010

WebDataGrid Numeric Pager Truncates List of Page Numbers

The WebDataGrid Numeric Pager was truncating the list of page numbers after reaching the end of the one line (table width) allocated for the pager display, as shown in the example below. There were scroll bars for the height and width of the data records, but no way to scroll past the end of the line of numbers and see page 21 in this example:



My solution was to create the following Css

<style type="text/css">
.tallPager {
height: 100px;
word-wrap: break-word;
text-align:left;
}
</style>

and apply it to the Paging property


<Behaviors>
<ig:Paging PageSize="25" PagerMode="Numeric" EnableInheritance="True"
PagerCssClass="tallPager" />

etc...

The following shows the pager section for a different table, with the PagerCssClass ="tallPager"


Note: Word wraps can occur in the middle of a page number like 108:


Fortunately, I have a higher class of users and they were able to deal with that.

Monday, May 17, 2010

tsql INSERT INTO for bulk copy of records from SqlServer table to table

I have been using tsql

Select * into Tbl2 from Tbl1 where FName = 'David'

for a long time, as a shortcut to create new table Tbl2, a copy of Tbl1 including schema and data.

I'm glad I finally found out about :

Insert into Tbl2 ( LastName , FirstName , AdmitDate) select Last, First, RevDate from Tbl1 where FName = 'David'

to use when Tbl2 is already in existence.

Friday, May 14, 2010

Calling all Technical Women in Technology for...

What we have all been waiting for ...

A NJ Technical Women in Technology
Event



Register Now ->


Recommended Audiences: IT Professionals, Administrators, Developers, Architects


Are you a Technical Women in Technology?

Are you tired of always being surrounded by technical males that don't ____ (fill in the blank)?

Are you tired of trying to explain your technical issues to other women that just don't get it?

Are you looking to connect with other women with common interests?


Then, you may be interested in helping to form a Technical Women in Technology Group...

Refreshments: Appetizers & Water/Soda

Sponsors: Microsoft / SetFocus

Purpose:

To allow NJ Technical Women in Technology to meet and to discuss a future direction for a group




Event Updates: updates

Agenda:

Overview

Attendee Introductions

Panel Discussion (2-3 women sharing their experiences as a Technical Women in Technology

Future Direction Discussion - In-Person and/or Virtual meetings, frequency, meeting content, etc.



For Additional Information about how you can help kick start this community, please email melissa[@]sqldiva.com.


Tuesday, April 27, 2010

Include a derived control in my aspx page

register control at top of page giving it a TagPrefix:


<%@ Register Assembly="iProjectName" Namespace="iNamespceInCsFile" TagPrefix="ifc" %>



use tag prefix and control name in aspx


<ig:TemplateDataField Key="key1" Width="30px">
<ItemTemplate>
<ifc:CtrlClass ID="id1" runat="server" Text='<%# Eval "BoundCol1") %>' />
</ItemTemplate>
</ig:TemplateDataField>



"CtrlClass" is the derived control class name, which is in a cs file name doesn't matter, but namespace is "iNamespceInCsFile" in project ="iProjectName".

public class Comment2 : TextBox
{ etc ...

Tuesday, March 23, 2010

Comparison of ig bound Templated Checkbox to boolean BoundDataField


Shows up as text "true" or "false":
<ig:BoundDataField DataFieldName="IsCostSaving" Key="IsCostSaving" width="30px">
<Header Text="Cost Saving" />
</ig:BoundDataField>

Shows up as a checkbox with checked value picked up from bound field:
<ig:TemplateDataField Key="cb1" width="30px">
<Header Text="Cost Saving" />
<ItemTemplate>
<asp:CheckBox ID="cb1" runat="server" Checked='<%# Eval("IsCostSaving") %>' Enabled="false" />
</ItemTemplate>
</ig:TemplateDataField>

Monday, March 22, 2010

Looping thru Infragistics WebDataGrid on the Server



Took me a while to find this. With some help from ig, thank you Chandradeep!



protected void Button1_Click(object sender, EventArgs e)
{
// loop thru selected cells and get their values
foreach (GridRecordItem itm in WebDataGrid1.Behaviors.Selection.SelectedCells)
{
object ttt = itm.Text ;
}

// example of looping thru selected rows and getting values of columns
foreach (GridRecord row in WebDataGrid1.Behaviors.Selection.SelectedRows)
{
object ttt = row;
GridRecordItem itm = row.Items[0];
string sffssdf = itm.Text;
itm = row.Items[1];
sffssdf = itm.Text;
itm = row.Items[2];
sffssdf = itm.Text;
}

// example of looping thru all rows and getting values of columns
foreach (GridRecord row in WebDataGrid1.Rows)
// foreach (GridRecordItem row in WebDataGrid1.Behaviors.Selection.SelectedCells)
{
object ttt = row;
GridRecordItem itm = row.Items[0];

string sffssdf = itm.Text;
itm = row.Items[1];
sffssdf = itm.Text;
itm = row.Items[2];
sffssdf = itm.Text;
}

// example of looping thru all rows and getting values of a checkbox in a column template field!!!!!
foreach (GridRecord row in WebDataGrid1.Rows)
// foreach (GridRecordItem row in WebDataGrid1.Behaviors.Selection.SelectedCells)
{
CheckBox theCB = (CheckBox)row.Items[0].FindControl("cb1");
bool ischecked = theCB.Checked;
object ttt = row;
GridRecordItem itm = row.Items[0];


string sffssdf = itm.Text;
itm = row.Items[1];
sffssdf = itm.Text;
itm = row.Items[2];
sffssdf = itm.Text;
}


}

Tuesday, March 16, 2010

Case sensitive column contents in SqlServer

Use the following t-sql code to make the contents of a column case sensitive regardless of the default db setting:

alter table TheTableName alter column TheColumnName TypeOfColEgVarchar(20)OrChar(6) collate Latin1_General_CS_AS

for example:
alter table People alter column LastName varchar(20) collate Latin1_General_CS_AS

Am using this in SqlServer 2005.

Thursday, January 28, 2010

Leading zeros in tsql

select right ('StringOfZerosAsManyAsMaxNeededMoreIsOK'
+ cast ( AnIntegerLiteralOrIntVariable as varchar)
, IntLiteralWhichIsTotalLengthOfNeededString)

declare @counter int
set @counter = 126
select right ('000000' + cast ( @counter as varchar) , 6 )

result:
000126


declare @counter int
set @counter = 12345678
select right ('000000000' + cast ( @counter as varchar) , 6 )

result:
345678



declare @counter int
set @counter = 123
select right ('00' + cast ( @counter as varchar) , 6 )

result:
00123



declare @counter int
set @counter = 123
select right ('0000' + cast ( 123 as varchar) , 9 )

result:
000126

Thursday, January 14, 2010

Crystal Reports like in db selection formula

{vTimeTrackDataAll4.ContactName} like '*'+{?pEmpName}+'*' and
{vTimeTrackDataAll4.StartTime} >= {?pStartDate} and
{vTimeTrackDataAll4.StartTime} <= {?pEndDate}

Wednesday, January 13, 2010

javascript on mouseover lv and doubleclick event

protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
// not uploaded data
// this is done everytime the page is refreshed.

if (e.Item.ItemType == ListViewItemType.DataItem)
{


if (res & e.Row.DataItemIndex == theRowIndex)
{
GridView1.Rows[theRowIndex].Attributes.Add("onmouseover", "this.style.backgroundColor='PeachPuff'");
GridView1.Rows[theRowIndex].Attributes.Add("onmouseout", "this.style.backgroundColor='Beige'");
}

// Get the LinkButton control in the 9th cell
LinkButton _doubleClickButton = (LinkButton)e.Row.Cells[9].Controls[0];
// Get the javascript which is assigned to this LinkButton
string _jsDouble =
ClientScript.GetPostBackClientHyperlink(_doubleClickButton, "");
// Add this JavaScript to the ondblclick Attribute of the row
e.Row.Attributes["ondblclick"] = _jsDouble;

right click already defined
LinkButton _rightClickButton = (LinkButton)e.Row.Cells[10].Controls[0];
Get the javascript which is assigned to this LinkButton
string _jsDouble2 =
ClientScript.GetPostBackClientHyperlink(_rightClickButton, "");
Add this JavaScript to the ondblclick Attribute of the row
e.Row.Attributes["mousemove"] = _jsDouble2;
}
}

Monday, January 11, 2010

Adding a UserControl to a Placeholder Dynamically

So I was trying to dynamically generate my asp.net page by newing a UserControl and adding it to a Placeholder on Page_Load:

ucSelectMed ucMySelectMed = new ucSelectMed();
phSelectMed.Controls.Add(ucMySelectMed);

Ran the project, nothing was on the page.

Was really confused because the following works:

TextBox tb = new TextBox();
phSelectMed.Controls.Add(tb);

Anyway, what was needed is:

ucSelectMed ucMySelectMed = (ucSelectMed)LoadControl("ucSelectMed.ascx");
phSelectMed.Controls.Add(ucMySelectMed);

Monday, January 4, 2010

To Gac or Not To Gac

Gac location is c:\windows\assembly

Best post I have seen on this:

http://justmyopinion.cilyok.net/?p=406