Link to home
Start Free TrialLog in
Avatar of narangps
narangps

asked on

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'productid'.

I am getting error as above.What i am doing is trying to populate the gridview header and footer .I am tring to populate a combo productname,a textbox for productid and unitprice for productid all based on productname.

Thanks
Parminder
Default.aspx.cs
 CustomerCls customer=new CustomerCls();   
 protected void grdAdd_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        DataTable dtorder = customer.FetchProducts();
 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList ddlnewproductname = (DropDownList)e.Row.FindControl("ddlnewProductName");
            if (ddlnewproductname != null)
            {
                ddlnewproductname.DataSource = customer.FetchProducts();
                ddlnewproductname.DataBind();
                ddlnewproductname.SelectedValue = grdAdd.DataKeys[e.Row.RowIndex].Values[1].ToString();
                
            }
        }
 
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            DropDownList ddlnewproductname = (DropDownList)e.Row.FindControl("ddlnewproductname");
            ddlnewproductname.DataSource = customer.FetchProducts();
            ddlnewproductname.DataBind();
        } 
 
     }
--------------
HTML Page
   <asp:TemplateField HeaderText="productid"  > 
            <EditItemTemplate> 
                <asp:TextBox ID="txtproductid" runat="server" Text='<%# Eval("productid") %>'></asp:TextBox> 
            </EditItemTemplate> 
            
            <FooterTemplate> 
                <asp:TextBox ID="txtproductid" runat="server" > </asp:TextBox> 
            </FooterTemplate> 
            
            <ItemTemplate> 
                 <asp:Label ID="lblproductid" runat="server" Text='<%# Bind("productid") %>'></asp:Label> 
            </ItemTemplate> 
            <HeaderStyle HorizontalAlign="Left" />
        </asp:TemplateField> 
        
        
        
        
        
        
        <asp:TemplateField HeaderText="Product Name"> 
<%--            <EditItemTemplate> 
                 <asp:DropDownList ID="ddlproductName" runat="server" DataTextField="productname" DataValueField="productname"> </asp:DropDownList> 
            </EditItemTemplate>--%> 
            <ItemTemplate> 
                <asp:Label ID="lblProductName" runat="server" Text='<%# Eval("productname") %>'></asp:Label> 
            </ItemTemplate> 
            <FooterTemplate> 
                <asp:DropDownList ID="ddlnewProductName" runat="server" DataTextField="ddlnewProductName" DataValueField="ddlnewProductName"> </asp:DropDownList> 
            </FooterTemplate> 
            <HeaderStyle HorizontalAlign="Left" />
        </asp:TemplateField> 
 
        <asp:TemplateField HeaderText="Unit Price"> 
            <EditItemTemplate> 
                 <asp:TextBox ID="txtunitprice" runat="server" Text='<%# Bind("unitprice") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <ItemTemplate> 
                <asp:Label ID="lblUnitPrice" runat="server" Text='<%# Bind("unitprice") %>'></asp:Label> 
            </ItemTemplate> 
            <HeaderStyle HorizontalAlign="Left" />
        </asp:TemplateField> 
----------------------------
customerccls 
    public DataTable FetchProducts()
    {
        DataTable mydata = new DataTable();
        using (SqlConnection cn2 = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDbConn"].ToString()))
        {
            try
            {
                SqlCommand cmd = new SqlCommand("sp_select_product", cn2);
                cmd.CommandType = CommandType.StoredProcedure;
 
                cn2.Open();
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                adapter.Fill(mydata);
                cn2.Close();
            }
            catch
            {
                cn2.Close();
            }
            return mydata;
 
 
        }
    }
---------------------------------------
stored proc
 
select productid as productid, productname as productname  ,
CONVERT(decimal(10,2),unitprice) as unitprice
from [Products]

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of narangps
narangps

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial