reference not set to an instance of an object in Datagrid

jmjyiannis

Member
Joined
Jun 27, 2004
Messages
16
Programming Experience
Beginner
Daragrid and Links

Hello Experts!

I want to construct a Datagrid and for each item of the table created in this datagrid to have a link. Let's say a Datagrid

<asp: Datagrid id="dgCustomers" runat="server"
</Datagrid>

But for each Customer I want to have a Link based on his id.

Where should I put the <a href="....?id=..."> ?????

Any Suggestions???
 
Last edited:

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
Here's some sample code for a dataTable Named 'dtCustomers' with two fields named 'CustId' and 'CustName':

VB.NET:
<asp:Datagrid id="dgCustomers" runat="server" AutoGenerateColumns="False" DataSource="dtCustomers">
    <Columns>
        <asp:TemplateColumn HeaderText="Customer" itemstyle-width="50%">
            <ItemTemplate>
                <asp:Label runat="server" 
                  Text='<%#"<a href=somePage.aspx?id=" + 
                     DataBinder.Eval(Container, "DataItem.CustId")+">"+
                     DataBinder.Eval(Container, "DataItem.CustName")+"</a>" %>'>
                </asp:Label>
            </ItemTemplate>
        </asp:TemplateColumn>
    </Columns>
</asp:Datagrid>
You can set the dataSource either as I've shown (in the parameters of the dataGrid) or via code (script).
 
Top Bottom