Tuesday, June 29, 2010

Binding a java script when adding rows to data grid view

protected void gvInvoiceItemList_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlPromoType = (DropDownList)e.Row.FindControl("ddlPramotionType");
TextBox txtNoofPacks = (TextBox)e.Row.FindControl("txtNoOfPacks");
TextBox txtDiscounts = (TextBox)e.Row.FindControl("txtDiscount");

if (ddlPromoType != null && txtNoofPacks != null && txtDiscounts != null)
{
string function = "DisableTextboxes('" + txtNoofPacks.ClientID + "','" + txtDiscounts.ClientID + "','" + ddlPromoType.ClientID + "')";

//add a java script to drop down list

ddlPromoType.Attributes.Add("onchange", function);
ClientScript.RegisterStartupScript(this.GetType(), ddlPromoType.ClientID, "");

}
}
}
catch (Exception ex)
{

}
}


// java script

No comments:

Post a Comment