Asp VB Gridview and binging/using multiple Datafields

Soldato
Joined
8 Mar 2005
Posts
3,674
Location
London, UK
I would think this quite simple but no matter what or how I do I cannot seem to get this to this to work / render in an expected way.

I'm want to create a mailto link within a gridview which uses data from that column but I wish ti include data from another column within the subject line within that mailto link.

Gridviewe code with nothing behind which produces the mailto link.
Code:
  <asp:BoundField DataField="GroupName" HeaderText="GroupName" SortExpression="GroupName"></asp:BoundField>
                <asp:BoundField DataField="MGroup" HeaderText="MGroup" SortExpression="MGroup"></asp:BoundField>
                <asp:BoundField DataField="Created" HeaderText="Created" SortExpression="Created"></asp:BoundField>
                  <asp:BoundField DataField="MGroupEmail" HeaderText="Email"
                           SortExpression="MGroupEmail"
                        DataFormatString='<a href="mailto:{0}
                             ?subject=User%20request%20for%20Active%20Directory%20Group">Request Access</a>'
                           HtmlEncode="false"
                           HtmlEncodeFormatString="false" Visible="true"  >
                             <controlstyle borderstyle="Double" />
                             <ItemStyle BorderStyle="Double" Font-Bold="True" />
                </asp:BoundField>
I wish to add the MGROUP column into the subject line, ala <%# Eval("MGROUP ") %> or somesuch but I cannot seem to incorporate that without concatting it or displaying it. Various posts suggest I need to use templatefield instead of boundfields but then I lose DataFormatString and the mailto option so have to go with Hyperlink.

This is what I have thus far
Code:
   <asp:TemplateField HeaderText="Email2" SortExpression="Email2">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("MGroup") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("GroupName") %>'></asp:Label>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("MGroupEmail") %>'></asp:Label>
                     <asp:HyperLink ID="hypEmail" runat="server"
                                Text = '<%# DataBinder.Eval(Container.DataItem, "MGroupEmail")%>'
                                NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "MGroupEmail","mailto:{0}?subject=User%20request%20for%20Active%20Directory%20Group%20") %>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
This currently displays the datafields I want along with the mailto link without the second column data. Ultimately all I want displayed within the gridview is a mailto link "email".

Any pointers, as always, most welcome!
TIA.

E: sorted it with

Code:
NavigateUrl='<%# string.Format("mailto:{0}
                         ?subject={1}", Eval("MGroupEmail"),Eval("MGroup")) %>'
 
Last edited:
Back
Top Bottom