2011-01-09 15 views
0

私はasp.netデータリストの更新

コードビハインド以下の私のコード与え更新command.Iのクリックでデータリストコントロールの項目テンプレートに編集項目テンプレートから可能なバインドデータはないです。

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> 

私はこれを行うme.can私は助けworking.Pleaseされていない項目template.aboveコードに患者の値を取得することはできませんか?

答えて

0

[更新]ボタンがクリックされた時点でItemTemplateは存在しません。それは次のポストバックに現れます。

データベースを更新するには、Updateイベントを使用する必要があります。次のポストバックでは、データベースからItemListコントロールにデータをバインドします。

関連する問題