Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gridview binding

Status
Not open for further replies.

vcllvc

Programmer
Jul 12, 2001
136
US
If I have a gridview, can I bind two fields into one field like below:

<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" Text='Customer is <%#Eval("CustID") %><%#Eval("CustName") %>'>

</asp:LinkButton>

</ItemTemplate>
 
set the OnRowDataBoundevent for the gridview
Code:
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
</asp:GridView>
then in the code behind
Code:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowIndex > -1)
    {
        LinkButton link = e.Row.FindControl("LinkButton1") as LinkButton;
        DataRowView row = e.Row.DataItem as DataRowView;
        link.Text = string.Concat(row["[CustID]"].ToString(), " ", row["CustName"].ToString());
    }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Or you could simply do it in the original SQL Statement


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top