2017-04-14 2 views
0

asp.net 웹 양식의 listview가 있습니다. 단추를 클릭 한 후 행을 선택하고 업데이트를 선택하고 싶습니다.
이것을 위해 나는 Checkbox/CheckboxList를 사용하고 싶다. 그러나 나는 행에 대한 정보를 선택한 행의 열에서 Checkbox/CheckboxList 항목으로 보내는 방법을 이해하지 못합니다.
어떻게 확인란을 선택/체크 박스를 사용하여 행을 선택하고 업데이트 할 수 있습니까?
Asp.net Linq Entity Framework를 사용합니다.
내 코드ListView에서 선택한 행을 업데이트하는 방법

<asp:Button ID="ButtonTest" runat ="server" OnClick="ButtonTest_Click" /> 
 
<asp:ListView ID="ListView2" ItemType="DocCat.Models.ReqInf" SelectMethod="GetReqF" OnItemDataBound="ListView2_ItemDataBound" 
 
      DataKeyNames="requestN" EnableViewState="true" runat="server" UpdateMethod="ListView2_UpdateItem" DeleteMethod="ListView2_DeleteItem" InsertMethod="ListView2_InsertItem"> 
 
      <LayoutTemplate> 
 
       <div class="outerContainer" style="overflow: scroll"> 
 
        <table id="docTable"> 
 
         <thead> 
 
          <tr> 
 
           <th> 
 
            Выбрать 
 
           </th> 
 
           <th>First</th> 
 
           <th>Request</th> 
 
           <th>Third</th> 
 
           <th>Four</th> 
 
          </tr> 
 
         </thead> 
 
         <tbody runat="server" id="itemPlaceholder"></tbody> 
 
        </table> 
 
       </div> 
 
       
 
      </LayoutTemplate> 
 

 
      <ItemTemplate> 
 
       <tr> 
 
        <td> <asp:CheckBoxList runat="server" ID="CheckNew" ><asp:ListItem>Выбрать</asp:ListItem></asp:CheckBoxList></td> 
 
        <td> 
 
       </td> 
 
        <td><%# Item.BirthDate.Date%></td> 
 
        <td><%# Item.F1 %></td> 
 
        <td><%# Item.F2 %></td> 
 
        <td><%# Item.F3 %></td> 
 
       </tr> 
 
      </ItemTemplate> 
 
     </asp:ListView>

Checkboxlist 항목과 문자열 selectedItems를에 표시되지 않습니다

선택된 행 :

 CheckBoxList cblRoles = ListView2.Items[0].FindControl("CheckNew") as CheckBoxList; 
 
     
 
     string selectedItems = ""; 
 

 
     for (int i = 0; i < cblRoles.Items.Count; i++) 
 
     { 
 
      if (cblRoles.Items[i].Selected) 
 
      { 
 
       selectedItems = selectedItems + cblRoles.Items[i].Value + ","; 
 
      } 
 
     } 
 
     
 
     
 

답변

0

이 체크 박스를 찾는 것이 었습니다, 난 그냥이를 놓쳤다.

내 button_click 방법 :

  List<int> ls = new List<int>(); 

      { 

       foreach (ListViewDataItem item in this.ListView2.Items) 
       { 
        if (item.ItemType == ListViewItemType.DataItem) 
        { 
         CheckBox chkRow = item.FindControl("CheckBox") as CheckBox; 

         if (chkRow.Checked) 
         { 
          int request = int.Parse((item.FindControl("FirstFind") as Label).Text.Trim()); 

          ls.Add(request); 


         } 
        } 
       } 


       repository.Approved(ls, newstat); 

업데이트 방법

public void Approved(List<int> list,int stat) 
     { 


      var friends = context.Requery.Where(f => list.Contains(f.parametr)).ToList(); 

      friends.ForEach(a => 
      { 
       a.par1 = 0; 
       a.par2 = stat; 
      }); 


      context.SaveChanges(); 

     } 
0

나는 최근에 이러한 종류의 사용 UI. 처음에는 테이블 UI를 만들었고 코드 뒤에 테이블 채우기 메서드를 만들었습니다. ADO.net을 데이터 액세스에 사용했습니다.

참고 : 버튼을 클릭 한 후 데이터를 가져오고 데이터를 업데이트하기위한 저장된 procs를 만듭니다.

Step1 : 해당 개체를 확인란에 채우지 만 라디오 버튼을 사용합니다.

    using (mTableRow = new HtmlTableRow()){ 
        { 

         #region Radio Button 

         using (HtmlTableCell lTableCell = new HtmlTableCell()) 
         { 
          RadioButton mradioButton = new RadioButton(); 
           mradioButton.ID = "Radio" + listInfo.ID; 

           mradioButton.GroupName = "rowSelector1"; 
           mradioButton.AutoPostBack = true; 
           mradioButton.Checked = false; 

           mradioButton.CheckedChanged += new EventHandler(AvailableRadioButton_CheckedChanged); 

           lTableCell.Attributes["class"] = "RadioButton"; 
           lTableCell.Controls.Add(mradioButton); 

           mTableRow.Cells.Add(lTableCell); 

           #endregion 
         // add all the remaining columns 
          // add table row to the table. 

2 단계 : 확인란을 클릭하여 이벤트를 클릭하는 방법을 만듭니다.

foreach (ListViewDataItem item in this.ListView2.Items) 
       { 
        if (item.ItemType == ListViewItemType.DataItem) 
        { 

을하고 모두가 노력하고 있습니다 : 내 문제

+0

참고 : 여기에 귀하의 체크 박스 ID는 고유해야합니다. 따라서 테이블의 기본 키 열을 연결하고 쿼리 또는 저장 프로 시저에서 기본 키를 사용해야합니다. 그런 다음 행을 선택할 수 있습니다. – 123456

+0

고마워,하지만 난 Listview있어 –

관련 문제