0

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!

Edited by Bei_Mu_tian: n/a

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by __avd
0

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

Edited by Bei_Mu_tian: n/a

0

>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?

0

>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...

Attachments tha_thing.png 22.73 KB
1

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!

Votes + Comments
Cheers!!
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.