3
Answers

C#:Change repeater data based on dropdownlist

Fares Ayyad

Fares Ayyad

8y
299
1
Hello 
 
I'm working on project that have a repeater and a dropdownlist.
 
 
DropDownList with AutoPostBack:
  1. <asp:DropDownList ID="ddlTer" runat="server" AutoPostBack="true" ></asp:DropDownList>  

 This is the repeater in .aspx page:
  1. asp:Repeater ID="rptDep"  runat="server" >  
  2.                <HeaderTemplate>  
  3.                    <table class="table table-hover table-striped table-condensed table-bordered table-responsive" >  
  4.                     
  5.                         <tr>  
  6.                         <th>Deposit No.</th>  
  7.                         <th>Territory</th>  
  8.                         <th>Deposit Date</th>   
  9.                         <th>Custom Declaration No.</th>   
  10.                         <th>Goods Description</th>  
  11.                         <th>Units Balance</th>  
  12.                         <th>WT Balance</th>  
  13.                         <th>Goods Balance Amount(LC)</th>  
  14.                     </tr>  
  15.   
  16.                </HeaderTemplate>  
  17.   
  18.                 <ItemTemplate>  
  19.                    
  20.                        <tr>  
  21.                        <td>  <%#Eval("cdin_Serial") %></td>      
  22.                        <td><%#Eval("terr") %></td>  
  23.                        <td><%#Eval("customDec") %></td>  
  24.                        <td><%#Eval("cdin_startunstufdate") %></td>  
  25.                        <td><%#Eval("cdin_goodsDesc") %></td>  
  26.                        <td><%#Eval("unitsBal") %></td>  
  27.                        <td><%#Eval("wtBal") %></td>  
  28.                        <td><%#Eval("currBal") %></td>  
  29.                     </tr>   
  30.                 
  31.   
  32.                 </ItemTemplate>  
  33.   
  34.                 <FooterTemplate>  
  35.                     </table>  
  36.                 </FooterTemplate>  
  37.             </asp:Repeater>  
 How i populate Data in DropDownList:
  1. var ids = new List<int> { -1342177274, -1073741819, -805306364, -536870909, -268435454, 1, 268435456 };  
  2.          
  3.        var tc = (from t in db.Territories  
  4.                  where ids.Contains(t.Terr_TerritoryID)  
  5.                  select new  
  6.                  {  
  7.   
  8.                      terCapt = t.Terr_Caption,  
  9.                      terID = t.Terr_TerritoryID  
  10.   
  11.                  }  
  12.                  );  
  13.   
  14.        ddlTer.DataSource = tc.ToList();  
  15.        ddlTer.DataValueField = "terID";  
  16.        ddlTer.DataTextField = "terCapt";  
  17.        ddlTer.SelectedValue = "-1073741819";  
  18.        ddlTer.DataBind();  
 Integer declaration to know the select value.
  1. int selected = int.Parse(ddlTer.SelectedValue);    
 Query to select data from database, and passing the Selected value

  1.   
  2.     var query = (from cdin in db.CDIndexes  
  3.              join comp in db.Companies on cdin.cdin_CompanyId equals comp.Comp_CompanyId  
  4.              join terr in db.Territories on cdin.cdin_Secterr equals terr.Terr_TerritoryID  
  5.              join gds in db.Goods on cdin.cdin_CDIndexID equals gds.good_GoodsID  
  6.   
  7.              where cdin.cdin_Status == "InProgress" &&  
  8.              cdin.cdin_CompanyId == 83 &&  
  9.              cdin.cdin_Secterr == selected &&  
  10.              cdin.cdin_CDIndexID == 4 &&  
  11.              cdin.cdin_Deleted == null &&  
  12.              comp.Comp_Deleted == null //&& cdin.cdin_Secterr= -1073741819 &&  cdin.cdin_CompanyId=83  cdin.cdin_Deleted = null && comp.Comp_Deleted = null &&  
  13.              select new  
  14.              {  
  15.                  cdin_Serial = cdin.cdin_Serial,  
  16.                  cdin_startunstufdate = cdin.cdin_startunstufdate,  
  17.                  cdin_goodsDesc = cdin.cdin_goodsDesc,  
  18.                  terr = terr.Terr_Caption,  
  19.                  customDec = cdin.cdin_Customdeclar,  
  20.                  unitsBal = cdin.cdin_RemainPackages,  
  21.                  wtBal = cdin.cdin_RemainWT,  
  22.                  currBal = cdin.cdin_ActMortgageAmnt,  
  23.                  gdsDesc = gds.good_Name,  
  24.                  gdUnitBal = gds.good_RemainPackages,  
  25.                  gdWtBal = gds.good_RemainWT,  
  26.   
  27.              }  
  28. .ToList();  
 
 Binding the repeater:
  1. rptDep.DataSource = query; 
  2. rptDep.DataBind();  
 Note that : all the code above is warped by if(!isPostBack)
 
what i want is how to change the data in repater if the dropdown list selected item changed. 
 
 
Answers (3)