Reapeater Control按钮单击

时间:2018-02-19 13:39:48

标签: asp.net vb.net

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

enter image description here

代码:

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()

1 个答案:

答案 0 :(得分:0)

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")