1
votes

My asp.net application currently uses a Telerik RadGrid to show product data. At the top of the page, I have a dropdown list that will include 4 different categories. Based on the user's selection of category, the checkboxes in the grid will either become checked or not checked. The website's 1500 products will always show in the grid, it's the checkboxes that will be changing.

Ex: Product 1 is in Category A, therefore if a user clicks on Category B in the dropdown, the checkbox next to Product 1 will be unchecked. The only way that will be checked is if the user changes the dropdown to view the products currently in Category A.

I am having trouble trying to figure out how to approach this. For one, the line if (ProductInMarket.Checked = true) throws an error sayingThe name ProductInMarket' does not exist in the current context.` The second problem I have is that I can't figure out how to finish the UpdateMarket method. That's what happens when you take a lunch in the middle of coding. :/

This is what I have so far and I would really appreciate some help here.

<asp:DropDownList ID="MarketDropDownList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="MarketDropDownList_SelectedIndexChanged" AppendDataBoundItems="true">
 </asp:DropDownList>


<telerik:GridTemplateColumn AllowFiltering="true" HeaderText="Product ID" UniqueName="productid" ReadOnly="true">
 <HeaderTemplate>
   <asp:CheckBox ID="headerCheck" runat="server"                                      onClick="javascript:SelectDeselectAllCheckboxes(this);" />
 </HeaderTemplate>
 <ItemTemplate>
     <asp:Checkbox ID="ProductInMarket" runat="server" />
     <asp:HiddenField runat="server" ID="ProductID" />
  </ItemTemplate>
  </telerik:GridTemplateColumn>



private void UpdateMarket(string MarketID)
    {
        //add products to market when checked
        if (ProductInMarket.Checked = true)
        {
            string strConn = ConfigurationManager.ConnectionStrings["DBConnectingString"].ToString();
            using (SqlConnection con = new SqlConnection(strConn))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection = con;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "UPDATE table SET ProductID = @ProductID WHERE MarketID = @MarketID";
                 }
             }
         }
     }
2
So your drop down list is really doing a mass update of the 1,500 rows in the grid?Karl Anderson
Unfortunately, yes. I'd rather not do that because it seems like it would be super slow but that is what they want. Do you have a different suggestion?Jamie
So the drop down selection is really just a convenience so the user does not have to check/uncheck 1,500 times?Karl Anderson
You can use custom paging to limit number of records coming back at a time: demos.telerik.com/aspnet-ajax/grid/examples/programming/…IrishChieftain
@IrishChieftain - The OP has the opposite problem, updating 1,500 rows at the same time, the display is not the immediate problem the OP is facing.Karl Anderson

2 Answers

0
votes

I would recommend using batch updating via Performing Batch Operations Using DataAdapters.

Note: The UpdateBatchSize property is the key here, because it tells ADO.NET how many items to send in each batch. Setting it to zero will force the batch to be as large as possible, setting it to 1 will basically make it ignore batching, because it will send one at a time. You will need to play with this value to get the optimal value, taking into account performance and memory-usage (larger batches will use up more memory until it is cleaned up).

0
votes
<asp:DropDownList ID="MarketDropDownList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="MarketDropDownList_SelectedIndexChanged" AppendDataBoundItems="true">
 </asp:DropDownList>


<telerik:GridTemplateColumn AllowFiltering="true" HeaderText="Product ID" UniqueName="productid" ReadOnly="true">
 <HeaderTemplate>
   <asp:CheckBox ID="headerCheck" runat="server"                                      onClick="javascript:SelectDeselectAllCheckboxes(this);" />
 </HeaderTemplate>
 <ItemTemplate>
     <asp:Checkbox ID="ProductInMarket" runat="server" />
     <asp:HiddenField runat="server" ID="ProductID" />
  </ItemTemplate>
  </telerik:GridTemplateColumn>



private void UpdateMarket(string MarketID)
    {
        //add products to market when checked
        if (ProductInMarket.Checked = true)
        {
            string strConn = ConfigurationManager.ConnectionStrings["DBConnectingString"].ToString();
            using (SqlConnection con = new SqlConnection(strConn))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection = con;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "UPDATE table SET ProductID = @ProductID WHERE MarketID = @MarketID";
                 }
             }
         }
     }

try this

jsfiddle