Hello,
I'm trying to set the RadListBox DataKeyField within the code behind. When I attempt to assign the value I get the error:
[column_name] is neither a DataColumn nor a DataRelation for table DefaultView
The value returned from the string category variable exactly matches with the column name in the [Product] table.
Here is my applicable code:
aspx
code-behind:
I'm trying to set the RadListBox DataKeyField within the code behind. When I attempt to assign the value I get the error:
[column_name] is neither a DataColumn nor a DataRelation for table DefaultView
The value returned from the string category variable exactly matches with the column name in the [Product] table.
Here is my applicable code:
aspx
<telerik:RadListBox ID="RadListBox2" runat="server" Height="200" Width="300" AllowReorder="true" SelectionMode="Multiple" AllowDelete="true" DataSourceID="SelectedAttributes"></telerik:RadListBox><asp:SqlDataSource ID="SelectedAttributes" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" SelectCommand="SELECT @catName FROM [Product] WHERE [Number] = @Number"> <SelectParameters> <asp:Parameter Name="catName" /> </SelectParameters> <SelectParameters> <asp:ControlParameter Name="Number" ControlID="tbSearch" PropertyName="Text"/> </SelectParameters> </asp:SqlDataSource>code-behind:
//Get CategoryNameSqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString());SqlCommand commDetails = new SqlCommand("SELECT CategoryFieldName FROM [AttributeCategory] WHERE CategoryID = @CatID", conn1); conn1.Open(); commDetails.Parameters.Add("@CatID", SqlDbType.Int);commDetails.Parameters["@CatID"].Value = (RadListView1.SelectedItems[0] as RadListViewDataItem).GetDataKeyValue("CategoryID").ToString();object catName = (object)commDetails.ExecuteScalar();conn1.Close();string category = catName.ToString();SelectedAttributes.SelectParameters["catName"].DefaultValue = category;//Pass Data Keys For RadListBox2RadListBox2.DataKeyField = category;RadListBox2.DataSortField = category;RadListBox2.DataTextField = category;