Member Avatar for Bei_Mu_tian

Hello

I've got the following Problem:
I want to add a Templatefield at a specific column in a Gridview. Is this possible somehow without too much effort? I tried tons of things but haven't found a solution yet.

the thing is, that I add most columns via VB code. I have about 10 columns now. and now I want to add a templatefield to Column 11, because I need to use the "onClientClick" event for calling a JavaScript.

this is my gridview with a templatefield

<asp:GridView ID="gvLizenzUebersicht" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:linkbutton ID="lb1"  Text="<img src='../images/WebIcons/Computer_File_106.gif' border=0 title='Delete'>" runat="server" OnClientClick="return confirm('Möchten Sie wirklich löschen?');" CommandName="Delete"/>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

this is how I add and fill columns via VB

gvLizenzdateien.AllowSorting = False
                gvLizenzdateien.PageSize = 20
                gvLizenzdateien.AllowPaging = False
                gvLizenzdateien.AutoGenerateColumns = False

                SetEditCol(gvLizenzdateien)
                addField("DateiID", "DateiID", "DateiID", True, gvLizenzdateien)
                addField("ContentType", "ContentType", "ContentType", True, gvLizenzdateien)
                addField("Dateiname", "Dateiname", "Dateiname", True, gvLizenzdateien)
                addField("Bezeichnung", "Bezeichnung", "Bezeichnung", True, gvLizenzdateien)
                addField("Filesize", "Filesize in bytes", "Filesize", True, gvLizenzdateien)
                addField("Ersteller", "Uploader", "Ersteller", True, gvLizenzdateien)
                SetCheckBoxCol(gvLizenzdateien, "Select", True, True, "Aktiv")
                SetGridData()

would be awesome if there was a way to set a templatefield in the last column without rewriting all my "addfields" to other templatefields......:(

thanks for the help!

Recommended Answers

All 6 Replies

Insert a field at specific index.

GridView1.Columns.Insert(0, field1)
Member Avatar for Bei_Mu_tian

Insert a field at specific index.

GridView1.Columns.Insert(0, field1)

thank you very much :)!

but now I'm still kinda stuck with trying to connect the checkboxes within the newly added templatefield with the javascript which is in the html part...


(the whole Idea will be to create a column with only checkboxes in column 10 and if I click more than one checkbox, then the javascript notices that and wont allow it. there may only be one checkbox selected in that column. I already have the javascript, but cant use it inside the VB-Code...or at least I dont know how...)

>but now I'm still kinda stuck with trying to connect the checkboxes within the newly added templatefield with the javascript which is in the html part...

Can you maybe provide some more information about what it is you are trying to do?

Member Avatar for Bei_Mu_tian

>but now I'm still kinda stuck with trying to connect the checkboxes within the newly added templatefield with the javascript which is in the html part...

Can you maybe provide some more information about what it is you are trying to do?

added a pic to show what I wanna do...I hope I'm not making a complete fool of myself :confused:

I'm aware that I could add ALL templatefields via html...but I don't wanna do that...only the first and last column...

Member Avatar for Bei_Mu_tian

I went another way, since noone responded!
I put a counter behind it, that gave out a message, once more than one checkbox was enabled...it's not pretty, but it works!

commented: Cheers!! +7

Sorry!

I was confused by reading,

I'm aware that I could add ALL templatefields via html...but I don't wanna do that...only the first and last column...

I think you want to add something into templatefield that ensure a single checkbox can be selected.

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.