hi,
i am trying to calculation in radgrid by some sample available in telerik site but getting error
System.NullReferenceException: Object reference not set to an instance of an object.
in my grid label display in label column on selection of dropdown and quantity insert by user and output should come in some other column label amount.
now just tell me where is the prob???
i am trying to calculation in radgrid by some sample available in telerik site but getting error
System.NullReferenceException: Object reference not set to an instance of an object.
in my grid label display in label column on selection of dropdown and quantity insert by user and output should come in some other column label amount.
protected void radGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem item = (GridDataItem)e.Item; DropDownList list = (DropDownList)item.FindControl("ddl1"); list.Items.Insert(0, new ListItem("select", "-1")); SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["chalk_hillConnectionString"].ConnectionString); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand("select product_name from product_detail", con); DataSet ds = new DataSet(); da.Fill(ds); list.DataSource = ds; list.DataBind(); //For calculate item Amount.... Label lbl_Rate = (Label)item.FindControl("lblRate"); TextBox txt_Quantity = (TextBox)item.FindControl("txtQuantity"); Label lbl_Amount = (Label)item.FindControl("lblAmount"); txt_Quantity.Attributes.Add("onFocusout", "return show('" + txt_Quantity.ClientID + "','" + lbl_Rate.ClientID + "','" + lbl_Amount.ClientID + "')"); lbl_Rate.Attributes.Add("onFocusout", "return show('" + txt_Quantity.ClientID + "','" + lbl_Rate.ClientID + "','" + lbl_Amount.ClientID + "')"); lbl_Amount.Attributes.Add("onFocusout", "return show('" + txt_Quantity.ClientID + "','" + lbl_Rate.ClientID + "','" + lbl_Amount.ClientID + "')"); } }<telerik:RadGrid ID="radGrid1" runat="server" OnInsertCommand="radGrid1_InsertCommand" AutoGenerateColumns="False" GridLines="None" AllowMultiRowEdit="True" AllowAutomaticInserts="true" OnItemDataBound="radGrid1_ItemDataBound" OnNeedDataSource="radGrid1_NeedDataSource"> <MasterTableView AutoGenerateColumns="false" EditMode="InPlace" ShowFooter="false" CommandItemDisplay="Top" OnPreRender="radGrid1_PreRender"> <Columns> <telerik:GridTemplateColumn HeaderText="Product Name" UniqueName="Product_Name"> <ItemTemplate> <asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true" DataTextField="product_Name" DataValueField="product_Name" OnSelectedIndexChanged="ddl1_SelectedIndexChanged"> </asp:DropDownList> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderText="Product_rate"> <ItemTemplate> <asp:Label ID="lblrate" runat="server"></asp:Label> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderText="Product Quantity"> <EditItemTemplate> <asp:TextBox ID="txtQuantity" runat="server"/> </EditItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderText="Product Amount"> <ItemTemplate> <asp:Label ID="lblAmount" runat="server" /> </ItemTemplate> <FooterTemplate> <asp:Button ID="btn1" runat="server" Text="Add New Item" OnClick="btn1_click" /> </FooterTemplate> </telerik:GridTemplateColumn><script type="text/javascript" language="javascript"> function show(labelrate, labelamount, txtqty) { var txt_Quantity = $find(txtqty); var lbl_Rate = $find(labelrate) var lbl_Amount = $find(labelamount); var total = txt_Quantity.Getvalue() * lbl_Rate.Getvalue(); labelamount.Setvalue(total); } </script>