2011-01-09 2 views
0

내가asp.net DataList에 업데이트

코드 숨김 아래에있는 내 코드 주어진 업데이트 바로 명령의 클릭에 DataList에 제어 항목 템플릿을 편집 항목 템플릿에서 수 바인딩 데이터 아닙니다.

protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e) 
{ 

    DataTable dt = (DataTable)Session["time"]; 

    string patient = ((TextBox)e.Item.FindControl("TbxPatient")).Text; 

    ((Label)e.Item.FindControl("LblPatient")).Text = patient; 

    DataList1.EditItemIndex = -1; 

    DataList1.DataSource = dt; 

    DataList1.DataBind(); 
} 

ASPX 마크 업

<asp:DataList ID="DataList1" runat="server" Caption="Doctor1" OnEditCommand="DataList1_EditCommand" 
     BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" 
     CellPadding="3" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" 
     Font-Underline="False" ForeColor="Purple" GridLines="Vertical" OnCancelCommand="DataList1_CancelCommand" 
     OnItemDataBound="DataList1_ItemDataBound" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" 
     OnUpdateCommand="DataList1_UpdateCommand"> 
     <FooterStyle BackColor="#CCCCCC" ForeColor="Black" /> 
     <AlternatingItemStyle BackColor="#DCDCDC" /> 
     <ItemStyle BackColor="#EEEEEE" ForeColor="Black" /> 
     <EditItemTemplate> 
      <table style="width: 100%;"> 
       <tr> 
        <td> 
         Reg No 
        </td> 
        <td> 
         <asp:TextBox ID="TbxRegNo" runat="server"></asp:TextBox> 
        </td> 
        <td> 
         &nbsp; 
        </td> 
       </tr> 
       <tr> 
        <td> 
         Patient 
        </td> 
        <td> 
         <asp:TextBox ID="TbxPatient" runat="server"></asp:TextBox> 
        </td> 
        <td> 
         &nbsp; 
        </td> 
       </tr> 
       <tr> 
        <td> 
         Compliats 
        </td> 
        <td> 
         <asp:TextBox ID="TbxCompliant" runat="server"></asp:TextBox> 
        </td> 
        <td> 
         &nbsp; 
        </td> 
       </tr> 
       <tr> 
        <td> 
         Mob.No 
        </td> 
        <td> 
         <asp:TextBox ID="TbxNo" runat="server"></asp:TextBox> 
        </td> 
        <td> 
         &nbsp; 
        </td> 
       </tr> 
       <tr> 
        <td colspan="2"> 
         <asp:LinkButton ID="button2" runat="server" CommandName="update" OnClick="button2_Click" 
          Text="Update" /> 
         <asp:LinkButton ID="button3" runat="server" CommandName="Cancel" Text="Cancel" /> 
        </td> 
        <td> 
         &nbsp; 
        </td> 
       </tr> 
      </table> 
     </EditItemTemplate> 
     <SelectedItemStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /> 
     <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /> 
     <ItemTemplate> 
      <br /> 
      <table style="width: 100%;"> 
       <tr> 
        <td colspan="3"> 
         <asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"time") %>'></asp:Label> 
        </td> 
       </tr> 
       <tr> 
        <td colspan="3"> 
         <asp:Label ID="LblPatient" runat="server"></asp:Label> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         &nbsp; 
        </td> 
        <td> 
         <asp:LinkButton ID="LinkButton3" runat="server" CommandName="select">Select</asp:LinkButton> 
         <asp:LinkButton ID="button3" runat="server" CommandName="edit" Text="Edit" /> 
        </td> 
        <td> 
         &nbsp; 
        </td> 
       </tr> 
      </table> 
     </ItemTemplate> 
</asp:DataList> 

내가 이렇게 실례합니다 내가 도움 working.Please되지 않는 항목 template.above 코드에 대한 환자의 가치를 얻을 수없는 이유는 무엇입니까?

답변

0

업데이트 버튼을 클릭 할 때 ItemTemplate이 존재하지 않습니다. 그것은 다음 PostBack에 존재하게 될 것입니다.

데이터베이스를 업데이트하려면 Update 이벤트를 사용해야합니다. 다음 포스트 백에서 데이터베이스의 데이터를 ItemList 컨트롤로 데이터 바인딩합니다.