I have a delete button by createing <asp:ImageButton>. first row user cant delete the item so I dont want a delete button on first row? how can i do this?

<asp:DataList ID="DataList1" runat="server" DataKeyField="ID" OnDeleteCommand="DeleteCommand" RepeatColumns="2" RepeatLayout="Table" RepeatDirection="Horizontal">
    <ItemTemplate>
        <asp:ImageButton runat="server" ID="deleteIB" CommandName="Delete" ImageUrl="x-icon.png" />
        <%# DataBinder.Eval(Container.DataItem, "PRINT") %>
    </ItemTemplate>
</asp:DataList>

Protected Sub BindGridData()
        Dim dt As DataTable = New DataTable()
        dt.Columns.Add(New DataColumn("ID", GetType(Int32)))
        dt.Columns.Add(New DataColumn("PRINT", GetType(String)))
        Dim dr As DataRow
        ...
            While reader.Read()
                dr = dt.NewRow()
                dr(0) = reader(0)
                dr(1) = "<a href=''>[x]</a> reader(1)"
                dt.Rows.Add(dr)
            End While
           ...
End Sub

Recommended Answers

All 4 Replies

I don't see the full app but in the last vb.net app I did, the button has a name and a reference id number so it's possible to hide the one you need to hide (set visible to 0) and then not respond to in that button's handler.

Given the severe lack of the app's code, this is just me thinking out loud. I see you have many questions without answers. I wonder if it's the lack of sharing that hurting you or if few practice this system any more.

aw I see so the imagebutton has uqiue id's. Do you know how can I hide the first 3 imagebutton in the back end? thanks

<asp:DataList ID="DataList1" runat="server" DataKeyField="ID" OnDeleteCommand="DeleteCommand" RepeatColumns="2" RepeatLayout="Table" RepeatDirection="Horizontal">
    <ItemTemplate>
        <asp:ImageButton runat="server" ID="deleteIB" CommandName="Delete" ImageUrl="x-icon.png" />
        <%# DataBinder.Eval(Container.DataItem, "PRINT") %>
    </ItemTemplate>
</asp:DataList>

Protected Sub Delete(ByVal sender As Object, ByVal e As DataListCommandEventArgs)
    Dim getID As String = DataList1.DataKeys(e.Item.ItemIndex)
    ErrorL.Text = getID

    If getID = 1 Then
        //how to disable?
    End If
End Sub

Never mind guys.... I found the solution. Here is the solution incase anyone is having the same issue as me

The trick is to just use simple IF statment inside the Imagebutton tag. I knew the ID for the first row is always 4,5,6 so I have hard code it.

So now the first row's visible will be set to false. no need to mess around in the back end

<asp:DataList ID="DataList1" runat="server" DataKeyField="ID" OnDeleteCommand="DeleteCommand" RepeatColumns="3" RepeatLayout="Table" RepeatDirection="Horizontal" >
    <ItemTemplate>
        <asp:ImageButton runat="server" ID="deleteIB" visible='<%#  IF (Eval("ID") = 4 OR Eval("ID") = 5 OR Eval("ID") = 6, "false", "true") %>' ImageUrl="x-icon.png"  />
        <%# DataBinder.Eval(Container.DataItem, "PRINT") %>
    </ItemTemplate>
</asp:DataList>

Good to read that it's solved. Sorry but my aspfoo is weak. Not a system I've been working on for years now. I see "visible" did play a role so that part was right.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.