Learn dot net

August 29, 2006

Adding dropdownlist into datagrid on edit mode

Filed under: Learn — Aris Priyantoro @ 11:17 pm

I have confusing on adding dropdownlist into datagrid, here some references about that:

And now, i’m still in confusing to pick index of the selected record and associate into dropdownlist. I’ll try it again….

Update:
Here the code to associate index of dropdownlist:

/// 
/// Set Selected Item into combo
/// 
/// 
/// 
private void DtDetail_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
	if(e.Item.ItemType == ListItemType.EditItem)
	{
		DataRowView drv = (DataRowView) e.Item.DataItem;
		String code = drv["Code"].ToString();
		DropDownList ddl = (DropDownList) e.Item.FindControl("cmbItem");
		ddl.SelectedValue = code.Trim();

//manipulate width all textbox (using static variable)
		for (int i=0;i string ctl = "_ctl" + i.ToString().Trim();
			TextBox txtB1 = (TextBox) e.Item.FindControl(ctl);
			txtB1.Width = 50;
		}
	}
}

Client-Side textbox Calculation

Filed under: Tutorial — Aris Priyantoro @ 1:53 pm

javascript Code

script language=”javascript”>

function focusText(control) {
control.style.backgroundColor = “#ffffcc”;
}

function checkText(control) {
if(control.value == “” || isNaN(control.value)) {
control.focus();
focusText(control);
}

else {
control.style.backgroundColor = “#ffffff”;
Calculate();
}
}

function Calculate() {
var price = isNaN(document.frmAddDetail.txtPrice.value) ? 0 : document.frmAddDetail.txtPrice.value;
var qty = isNaN(document.frmAddDetail.txtQuantity.value) ? 0 : document.frmAddDetail.txtQuantity.value;
var disc = isNaN(document.frmAddDetail.txtDiscount.value) ? 0 : document.frmAddDetail.txtDiscount.value;

var discount = price * qty * disc / 100;

document.frmAddDetail.txtTotal.value = price * qty – discount;
}

script>

Aspx Code:

form id=”frmAddDetail” method=”post” runat=”server”>
 
h1>Add Detail Transactionh1>
P>
TABLE id=”tblAdd” style=”WIDTH: 552px; HEIGHT: 163px” cellSpacing=”1″ cellPadding=”1″
width=”552″ border=”0″>
TR>
TD style=”HEIGHT: 6px” noWrap>Item
TD>
TD style=”HEIGHT: 6px”>:TD>
TD style=”HEIGHT: 6px” noWrap>asp:dropdownlist id=”cmbItem” runat=”server” Width=”174px”>asp:dropdownlist>asp:requiredfieldvalidator id=”userValidate” runat=”server” ControlToValidate=”cmbItem” ErrorMessage=”Item Code required”>asp:requiredfieldvalidator>TD>
TR>
TR>
TD noWrap>PriceTD>
TD>:TD>
TD noWrap>asp:textbox id=”txtPrice” runat=”server” onFocus=”focusText(this)” onBlur=”checkText(this)”>asp:textbox>asp:requiredfieldvalidator id=”RequiredFieldValidator1″ runat=”server” ControlToValidate=”txtPrice” ErrorMessage=”Price must be filled”>asp:requiredfieldvalidator>TD>
TR>
TR>
TD noWrap>QuantityTD>
TD>:TD>
TD noWrap>asp:textbox id=”txtQuantity” runat=”server” onFocus=”focusText(this)” onBlur=”checkText(this)”>asp:textbox>asp:requiredfieldvalidator id=”Requiredfieldvalidator2″ runat=”server” ControlToValidate=”txtQuantity” ErrorMessage=”Quantity must be filled”>asp:requiredfieldvalidator>TD>
TR>
TR>
TD noWrap>DiscountTD>
TD>:TD>
TD noWrap>asp:textbox id=”txtDiscount” runat=”server” onFocus=”focusText(this)” onBlur=”checkText(this)”>0asp:textbox>asp:requiredfieldvalidator id=”Requiredfieldvalidator3″ runat=”server” ControlToValidate=”txtDiscount” ErrorMessage=”Discount minimum 0%”>asp:requiredfieldvalidator>TD>
TR>
TR>
TD noWrap>TotalTD>
TD>:TD>
TD noWrap>asp:textbox id=”txtTotal” runat=”server” onFocus=”checkText(this)” ReadOnly>asp:textbox>asp:requiredfieldvalidator id=”Requiredfieldvalidator4″ runat=”server” ControlToValidate=”txtQuantity” ErrorMessage=”Quantity must be filled”>asp:requiredfieldvalidator>TD>
TR>
TR>
TD noWrap colSpan=”3″>asp:button id=”btnSave” runat=”server” Text=”Save”>asp:button> 
asp:button id=”btnCancel” runat=”server” Text=”Cancel”>asp:button>TD>
TR>
TABLE>
asp:label id=”lblError” runat=”server” ForeColor=”Red” Visible=”False”>Labelasp:label>P>
form>

August 28, 2006

paging on datagrid

Filed under: Learn — Aris Priyantoro @ 5:20 pm

Here some code to apply paging on datagrid:

/// 
/// Apllying page changing
/// 
/// 
/// 
private void DtTransaction_PageIndexChanged(object source, 
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
	DataSet ds = (DataSet) this.Cache["dataset"];
	DtTransaction.CurrentPageIndex = e.NewPageIndex;

	DataTable dt = ds.Tables["TRANSACTION_HEADER"];
	DtTransaction.DataSource = dt.DefaultView;

	DtTransaction.DataBind();
}

August 25, 2006

Checkbox selection on datagrid

Filed under: Learn — Aris Priyantoro @ 11:47 am

do you want to check / uncheck all checkbox in a datagrid? Use this script:

foreach( DataGridItem di in DtUser.Items )
{
CheckBox cb = (CheckBox)di.Cells[0].Controls[1];
if( cb != null)
{
if (btnCheck.Text == “Check All”)
cb.Checked =
true;
else
cb.Checked = false;
}
}

August 24, 2006

Customize datagrid on web

Filed under: Learn — Aris Priyantoro @ 4:51 pm

We can customize datagrid on the web application. Here some explanation:

August 16, 2006

Login dinamically on Crystal Report

Filed under: Learn — Aris Priyantoro @ 2:49 am

More than one days i was confusing about login dinamically into database in crystal report. I was googling until i got some source in VB .NET. And now, i convert & modify the code into C# .NET. Here the Code:

///
/// Set Connection for all tables.
///
/// Report Document
private void SetConnection(CrystalDecisions.CrystalReports.Engine.ReportDocument rptDoc)
{
CrystalDecisions.CrystalReports.Engine.Database crDB = rptDoc.Database;
CrystalDecisions.CrystalReports.Engine.Tables crTables = crDB.Tables;
CrystalDecisions.Shared.TableLogOnInfo crTableLogInfo;
CrystalDecisions.Shared.ConnectionInfo crConnInfo =
new ConnectionInfo();

ClassDbConnection classDB = new ClassDbConnection();
classDB.ReadConfigurationFile();

// setting values
crConnInfo.DatabaseName = classDB.Database;
crConnInfo.ServerName = classDB.Hostname;
crConnInfo.UserID = classDB.Username;
crConnInfo.Password = classDB.Password;

foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
crTableLogInfo = crTable.LogOnInfo;
crTableLogInfo.ConnectionInfo = crConnInfo;
crTable.ApplyLogOnInfo(crTableLogInfo);
}
}

August 14, 2006

Create report using crystal report

Filed under: Learn — Aris Priyantoro @ 6:35 am

Now, i start to learn reporting using crystal report. Here some link to learn crystal report:

Passing parameter between form

Filed under: Learn — Aris Priyantoro @ 3:34 am

I’ve got problem to passing parameter from client to parent form. I’ve googling for a while, but i’m not found about it. But i found passing parameter from parent to client. Here the links:

By now, i can do that (passing parameter from client to parent form), here the litle sampe:

frmAdd = new frmAddDetail(dataSet1);
frmAdd.ShowDialog();
totalAmount = totalAmount + frmAdd.Total;

//counting amount data
lblTotal.Text = totalAmount.ToString();

//destroy form.
frmAdd.Dispose();

August 3, 2006

XML times

Filed under: Learn — Aris Priyantoro @ 7:29 am

Learn XML, visit here:

XML File sample:
http://www.cs.rpi.edu/~puninj/XMLJ/classes/class1/slide3-0.html

watchout your whitespace…. or you’ll get problems.

And absolutely ask to uncle google.

August 1, 2006

OOP Concept

Filed under: Learn — Aris Priyantoro @ 7:16 am
Next Page »

Blog at WordPress.com.