IranianCuriousBoy:a way to bind data of FormView in the GridView(in the sample you provided)
I don't think that you could use it directly as both controls (FormView & GridView) would bind to their own datasources. what you could do is extract data from the FormView and show it in the GridView. Again, you need to be aware that since this is a master-details scenario the FormView data would be repeated IF there are multiple rows for the GridView for the respective FormView DataItem. Also, since the sources are different they could be in different physical tables in the database and you would have to write separate queries to update any changes from the GridView to the FormView table for the particular value that you want to show in the GridView (or use stored procedures etc)
wire up the ItemCreated event of the FormView:
<asp:FormView ID="FormView1" runat="server" AllowPaging="True"
DataSourceID="LinqDataSource1" OnDataBound="FormView1_DataBound" OnItemCreated="FormView1_ItemCreated">
and the RowDataBound of the GridView, also add the TemplateField to show the label:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="LinqDataSource2" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="Quantity" HeaderText="Quantity" ReadOnly="True"
SortExpression="Quantity" />
<asp:BoundField DataField="OrderID" HeaderText="OrderID" ReadOnly="True"
SortExpression="OrderID" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID" ReadOnly="True"
SortExpression="ProductID" />
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
here's the codebehind:
string UnitsOnOrder = String.Empty;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void FormView1_ItemCreated(object sender, EventArgs e)
{
if (FormView1.DataItem != null)
{
UnitsOnOrder = DataBinder.Eval(FormView1.DataItem, "UnitsOnOrder").ToString();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl = e.Row.FindControl("Label1") as Label;
if (lbl != null)
{
lbl.Text = UnitsOnOrder;
}
}
}
if you work with VB.NET convert here: http://www.developerfusion.com/tools/convert/csharp-to-vb/