【问题标题】:Reapeater Control button click中继器控制按钮单击
【发布时间】:2018-02-19 13:39:48
【问题描述】:

当我点击投票按钮时,将插入详细信息,但我只想要插入特定按钮点击数据的所有页面详细信息。

代码:

Protected Sub vote(sender As Object, e As EventArgs) {
//( lblName,lbl_id ,lbl_name,Label1 this is all reapeater field id )

    Dim lblName As Label
    Dim lbl_id As Label
    Dim lbl_name As Label
    Dim Label1 As Label

    For Each item As RepeaterItem In rpt_path.Items
        lblName = CType(item.FindControl("lblName"), Label)
        lbl_id = CType(item.FindControl("lbl_id"), Label)
        lbl_name = CType(item.FindControl("lbl_name"), Label)
        Label1 = CType(item.FindControl("Label1"), Label)

        con=("Connection String")
        con.Open()

        Dim command As New OleDbCommand("insert into CFC(C_E_No,Name,Class_id,Party_id)values(@C_E_No,@Name,@Class_id,@Party_id)", con)
        command.Parameters.AddWithValue("(@C_E_No", CType(item.FindControl("lblName"), Label).Text)
        command.Parameters.AddWithValue("@Name", CType(item.FindControl("lbl_id"), Label).Text)
        command.Parameters.AddWithValue("@Class_id", CType(item.FindControl("lbl_name"), Label).Text)
        command.Parameters.AddWithValue("@Party_id", CType(item.FindControl("Label1"), Label).Text)

        command.ExecuteNonQuery()
        con.Close()

【问题讨论】:

  • 很确定你不想为每个重复所有的RepeaterItems。没有那个代码很难说。
  • 我们能看到转发器标记的源代码吗?
  • 您要插入所有数据吗?为了回答这个问题,我需要更清楚一些。如果您只想插入特定数据,则只需将该特定数据传递给查询或过程。

标签: asp.net vb.net


【解决方案1】:
Design
 <asp:Label ID="lbl_iid" runat="server" Text="Label" Visible="false"></asp:Label>
    </div>
        <asp:Label ID="lbl_iname" runat="server" Text="Label" Visible="false"></asp:Label>
        <asp:Label ID="lbl_icid" runat="server" Text="Label" Visible="false"></asp:Label>
        <asp:Label ID="lbl_ipid" runat="server" Text="Label" Visible="false"></asp:Label>
Coding on Vote Button Click
Protected Sub vote(sender As Object, e As EventArgs)

        Dim str As String = CType(sender, Button).CommandArgument
        Session("vid") = str
        MsgBox(Session("vid"))

       Connection String
        cmd = New OleDbCommand("select * from candi where C_E_No='" & str.ToString() & "' ")
        ds = New DataSet
        cmd.Connection = con
        con.Open()
        da = New OleDbDataAdapter(cmd)
        MsgBox(cmd.CommandText)
        da.Fill(ds, "candi")
        lbl_iid.Text = ds.Tables(0).Rows(0)(0)
        lbl_iname.Text = ds.Tables(0).Rows(0).Item(1).ToString()
        lbl_icid.Text = ds.Tables(0).Rows(0).Item(2).ToString()
        lbl_ipid.Text = ds.Tables(0).Rows(0).Item(4).ToString()

        con.Close()
     Connection String 
        cmd = New OleDbCommand("insert into CFC(Stu_E_No,C_E_No,Name,Class_id,Party_id)values('" & Session("stdid") & "','" & lbl_iid.Text & "','" & lbl_iname.Text & "','" & lbl_icid.Text & "','" & lbl_ipid.Text & "')  ")
        MsgBox(cmd.CommandText)
        cmd.Connection = con
        con.Open()
cmd.ExecuteNonQuery()
        con.Close()
        MsgBox("Succes")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多