0

次のデータリストがあります。

  <asp:DataList ID="dlAgents" runat="server" RepeatDirection="Horizontal" RepeatColumns="2" OnEditCommand="dlAgents_EditCommand" 
                                    Width="98%">

                                    <EditItemTemplate>
                                        <div class="creamebox">
                                            <table width="95%" border="0" align="center" cellpadding="3" cellspacing="2" style="padding-top: 10px">
                                                <tr>
                                                    <td width="32%" class="dottedline">
                                                        <strong class="NormalTextBig">
                                                            <asp:Label ID="lblName" runat="server" CssClass="NormalTextBig" ></asp:Label>
                                                        </strong>
                                                    </td>
                                                    <td width="68%" align="right" class="NormalTextBig dottedline">
                                                        <span class="FontColor1">No. of Clients:</span> 
                                                        <asp:LinkButton ID="lnkNoOfClients" runat="server" Text="3" CssClass="NormalTextBig FontColor6"></asp:LinkButton>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td height="2">
                                                    </td>
                                                    <td>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" valign="top" class="NormalText">
                                                        <strong>Address:</strong>
                                                    </td>
                                                    <td align="left" valign="top" class="NormalText">
                                                        <asp:TextBox ID="txtAddress" runat="server" ></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" valign="top" class="NormalText">
                                                        <strong>Contact:</strong>
                                                    </td>
                                                    <td align="left" valign="top" class="NormalText">
                                                        <asp:TextBox ID="txtContact" runat="server"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" valign="top" class="NormalText">
                                                        <strong>LoginId:</strong>
                                                    </td>
                                                    <td align="left" valign="top" class="NormalText">
                                                       <asp:LinkButton ID="lnkLoginID" runat="server"  CssClass="NormalTextBig FontColor6"  ></asp:LinkButton>

                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" valign="top" class="NormalText">
                                                        <a href="#" class="SmallerLink FontColor1">Reset Password </a>
                                                    </td>
                                                    <td align="right" valign="top" class="NormalText">

                                                        <asp:LinkButton  ID="ibEdit" runat="server"  alt="Edit" width="16" height="16" border="0" CommandArgument='<%#Eval("AgentId") %>' CommandName="CEdit"   ><img id="Img1" src="images/edit.png" runat="server" alt="" /></asp:LinkButton>
                                                        <asp:LinkButton  ID="ibDelete" runat="server" ImageUrl="images/delete.png" alt="Delete"  width="14" height="15" border="0"  CommandArgument='<%#Eval("AgentId") %>' CommandName="CDelete"  />        
                                                    </td>
                               </tr>
                                            </table>
                                        </div>
                                    </EditItemTemplate>

                                    <ItemTemplate>
                                       <div class="creamebox">
                                            <table width="95%" border="0" align="center" cellpadding="3" cellspacing="2" style="padding-top: 10px">
                                                <tr>
                                                    <td width="32%" class="dottedline">
                                                        <strong class="NormalTextBig">
                                                            <asp:Label ID="lblName" runat="server" CssClass="NormalTextBig" ></asp:Label>
                                                        </strong>
                                                    </td>
                                                    <td width="68%" align="right" class="NormalTextBig dottedline">
                                                        <span class="FontColor1">No. of Clients:</span> 
                                                        <asp:LinkButton ID="lnkNoOfClients" runat="server" Text="3" CssClass="NormalTextBig FontColor6"></asp:LinkButton>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td height="2">
                                                    </td>
                                                    <td>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" valign="top" class="NormalText">
                                                        <strong>Address:</strong>
                                                    </td>
                                                    <td align="left" valign="top" class="NormalText">
                                                       <asp:Label ID="lblAddress" runat="server" CssClass="NormalTextBig" ></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" valign="top" class="NormalText">
                                                        <strong>Contact:</strong>
                                                    </td>
                                                    <td align="left" valign="top" class="NormalText">
                                                        <asp:Label ID="lblContactNo" runat="server" CssClass="NormalTextBig" ></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" valign="top" class="NormalText">
                                                        <strong>LoginId:</strong>
                                                    </td>
                                                    <td align="left" valign="top" class="NormalText">
                                                       <asp:LinkButton ID="lnkLoginID" runat="server"  CssClass="NormalTextBig FontColor6"  ></asp:LinkButton>

                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" valign="top" class="NormalText">
                                                        <a href="#" class="SmallerLink FontColor1">Reset Password </a>
                                                    </td>
                                                    <td align="right" valign="top" class="NormalText">

                                                        <asp:LinkButton  ID="ibEdit" runat="server"  alt="Edit" width="16" height="16" border="0" CommandArgument='<%#Eval("AgentId") %>' CommandName="Edit"   ><img src="images/edit.png" runat="server" alt="" /></asp:LinkButton>
                                                        <asp:LinkButton  ID="ibDelete" runat="server" ImageUrl="images/delete.png" alt="Delete"  width="14" height="15" border="0"  CommandArgument='<%#Eval("AgentId") %>' CommandName="CDelete"  />        
                                                    </td>
                               </tr>
                                            </table>
                                        </div>
                                    </ItemTemplate>
                                </asp:DataList>

編集モードでテキスト ボックスの値を取得していません。

私は次のコードを持っています:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            bindList()
        End If
    End Sub
    Private Sub bindList()
        gc.BindGridView(dlAgents, "select * from AgentMaster")
    End Sub

    Protected Sub dlAgents_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlAgents.EditCommand
        dlAgents.EditItemIndex = e.Item.ItemIndex
        bindList()
    End Sub



Protected Sub dlAgents_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlAgents.ItemCommand
    If e.CommandName = "Edit" Then
        dlAgents.EditItemIndex = e.Item.ItemIndex
        bindList()
    End If
    If e.CommandName = "CEdit" Then
        gc.ExecuteCommand("update AgentMaster set Address='" & CType(e.Item.FindControl("txtAddress"), TextBox).Text & "' , ContactNo='" & CType(e.Item.FindControl("txtContact"), TextBox).Text & "' where agentid='" & e.CommandArgument & "'")
    End If
End Sub


Protected Sub dlAgents_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlAgents.ItemDataBound

    If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
        CType(e.Item.FindControl("lblName"), Label).Text = e.Item.DataItem("AgentName")
        CType(e.Item.FindControl("lblAddress"), Label).Text = e.Item.DataItem("Address")
        CType(e.Item.FindControl("lblContactNo"), Label).Text = e.Item.DataItem("ContactNo")
        CType(e.Item.FindControl("lnkLoginID"), LinkButton).Text = e.Item.DataItem("LoginEmailID")
    End If
End Sub

ItemCommand では、入力してもテキスト ボックスに空白の値が表示されます。

CType(e.Item.FindControl("txtAddress"), TextBox).Textこれにより、ItemCommand が空白になっていることがわかります。そのため、リストを更新できません。

私を助けてください。

C# での回答も役立ちます。

4

1 に答える 1