29 July 2008

Identify GridView RowIndex

//When we Click a grdView Row, then row index stored in a hidden Field
function GetGrvPersonalRowIndex(GRVRowIndex)
{
document.getElementById('ctl00_ContentPlaceHolder1_tbcDailyReporting_TabPanel1_HFGridviewRowIndex').value=GRVRowIndex;
}
-------In server side of asp page----------
protected void grvPersonal_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "javascript:GetGrvPersonalRowIndex(" + e.Row.RowIndex + ")");
}
}

Allow two decimal palace in textBox

function AllowOnlyTwoDecimalPlace(txtBox)
{
var num = parseFloat(txtBox.value);
txtBox.value = num.toFixed(2);
if (txtBox.value == 'NaN'){
txtBox.value = '';}

}

Focus to the control

ScriptManager sm = ScriptManager.GetCurrent(this);
sm.SetFocus(TextBox1);

To Identify Gridview Row Index in Row command

GridViewRow row = ((GridViewRow)((Control)e.CommandSource).Parent.Parent);
DropDownList ddlTest= (DropDownList)row.Cells[2].FindControl("ddlTest");