Answered by:
How to put repeater inside button?

Question
-
User1717218719 posted
I have decided to use a repeater instead of dropdown.
The code I have does not display anything at all in my web page currently. any ideas as to why this is happening?
Protected Sub Repeater1_ItemCommand(source As Object, e As RepeaterCommandEventArgs) Handles Repeater1.ItemCommand 'Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Me.BindRepeater() End If End Sub Private Sub BindRepeater() Dim strTaxCar As String = ConfigurationManager.ConnectionStrings("TaxCar").ConnectionString Using con As New SqlConnection(strTaxCar) Using cmd As New SqlCommand("SELECT TaxCar FROM RATD_ASI_D20180808_X2", con) Using sda As New SqlDataAdapter(cmd) Dim dt As New DataTable() sda.Fill(dt) Repeater1.DataSource = dt Repeater1.DataBind() End Using End Using End Using End Sub
<asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table> <tr> <th="col" style="width: 80px"> TaxCar</th> <%-- <th>Heading2</th> <th>Heading3</th>--%> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <asp:Label ID="TaxCar" runat="server" Text='<%# Eval("TaxCar") %>' /> </td> <td> <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("TaxCar") %>' Text='<%# Eval("TaxCar") %>'></asp:LinkButton> </td> <td>something </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater>
Also how would I code this To display only When I click this button?
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click 'Have repeater in here?? End Sub
Wednesday, April 24, 2019 8:00 AM
Answers
-
User1717218719 posted
I used this and got the anser!
Repeater1.DataSource = DataS.Tables(0)
Repeater1.DataBind()
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, April 24, 2019 10:34 AM
All replies
-
User-1174608757 posted
Hi E.RU,
According to your description, in usual, we could set the value of dropdownlist in gridview onrowdatabound event. Here is a demo, I hope it could help you.
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:TemplateField HeaderText="students"> <ItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> </form> </body> </html>
code behind:
Public Class query Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'bind table in database If Not IsPostBack Then Dim sql As String = "select * from students" GridView1.DataSource = sqlhelper.ExecuteDataTable(sql) GridView1.DataBind() End If End Sub Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then Dim ddl As DropDownList = CType(e.Row.FindControl("DropDownList1"), DropDownList) Dim sql1 As String = "select students from students" ddl.DataSource = sqlhelper.ExecuteDataTable(sql1) ddl.DataValueField = "students" ddl.DataBind() ddl.SelectedValue = e.Row.Cells(1).Text End If End Sub End Class
You could see:
Wednesday, April 24, 2019 10:17 AM -
User1717218719 posted
Sorry Wei, I changed my question as it didnt make sense what I was trying to do and a repeater would suit better
Wednesday, April 24, 2019 10:21 AM -
User1717218719 posted
I used this and got the anser!
Repeater1.DataSource = DataS.Tables(0)
Repeater1.DataBind()
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, April 24, 2019 10:34 AM