GridView-FormView (Master/Detail) Control not working...

  • Thread starter Thread starter yixiang
  • Start date Start date
Y

yixiang

Hi All,

I am a newbie to .NET programming and have been figuring out this
(master/detail) control.

However, it is not working...can someone please help me out???

<asp:GridView ID="GridView1" runat="server" DataKeyNames="ServiceID,
VersionNum" CellPadding="4" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None"
Height="81px" Width="16px">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="VersionNum"
HeaderText="VersionNum" ReadOnly="True" SortExpression="VersionNum" />
<asp:BoundField DataField="ServiceID"
HeaderText="ServiceID" ReadOnly="True" SortExpression="ServiceID" />
<asp:BoundField DataField="VersionDesc"
HeaderText="VersionDesc" SortExpression="VersionDesc" />
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString2.
ProviderName %>" SelectCommand="SELECT [ServiceID], [VersionNum],
[VersionDesc] FROM [w_ServiceVersion]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td style="width: 737px; height: 21px">
<asp:FormView ID="FormView1" runat="server"
DataKeyNames="ServiceID,VersionNum" DataSourceID="SqlDataSource2"
Width="555px">
<EditItemTemplate>
...........
</EditItemTemplate>
<InsertItemTemplate>
.............

</InsertItemTemplate>
<ItemTemplate>
............
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.
ProviderName %>" SelectCommand="SELECT ServiceID, VersionNum, VersionDesc
FROM dbo.w_ServiceVersion WHERE (ServiceID = ServiceID AND VersionNum =
VersionNum)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1"
Name="ServiceID" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="GridView1"
Name="VersionNum" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>

url:http://ureader.com/gp/1417-1.aspx
 
Howdy,

Seems you use composite data key on columns ServiceID and VersionNum, but
you two control parameters both point to the first value which in this case
is ServiceID (you can check what's passed to the query by handling
SqlDataSource2.Selecting event and checking e.Command.Parameters[0].Value,
e.Command.Parameters[1].Value). They point to the same value because of you
used GridView1.SelectedValue property which is a shortcut for
GridView1.SelectedDataKey.Values[0], what you need is to change the code to:

<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT ServiceID, VersionNum, VersionDesc FROM
dbo.w_ServiceVersion WHERE (ServiceID = ServiceID AND VersionNum =
VersionNum)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="ServiceID"
PropertyName="SelectedDataKey[0]" />
<asp:ControlParameter ControlID="GridView1" Name="VersionNum"
PropertyName="SelectedDataKey[1]" />
</SelectParameters>
</asp:SqlDataSource>

Hope this helps
--
Milosz


yixiang said:
Hi All,

I am a newbie to .NET programming and have been figuring out this
(master/detail) control.

However, it is not working...can someone please help me out???

<asp:GridView ID="GridView1" runat="server" DataKeyNames="ServiceID,
VersionNum" CellPadding="4" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None"
Height="81px" Width="16px">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="VersionNum"
HeaderText="VersionNum" ReadOnly="True" SortExpression="VersionNum" />
<asp:BoundField DataField="ServiceID"
HeaderText="ServiceID" ReadOnly="True" SortExpression="ServiceID" />
<asp:BoundField DataField="VersionDesc"
HeaderText="VersionDesc" SortExpression="VersionDesc" />
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString2.
ProviderName %>" SelectCommand="SELECT [ServiceID], [VersionNum],
[VersionDesc] FROM [w_ServiceVersion]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td style="width: 737px; height: 21px">
<asp:FormView ID="FormView1" runat="server"
DataKeyNames="ServiceID,VersionNum" DataSourceID="SqlDataSource2"
Width="555px">
<EditItemTemplate>
...........
</EditItemTemplate>
<InsertItemTemplate>
.............

</InsertItemTemplate>
<ItemTemplate>
............
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.
ProviderName %>" SelectCommand="SELECT ServiceID, VersionNum, VersionDesc
FROM dbo.w_ServiceVersion WHERE (ServiceID = ServiceID AND VersionNum =
VersionNum)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1"
Name="ServiceID" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="GridView1"
Name="VersionNum" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>

url:http://ureader.com/gp/1417-1.aspx
 
Back
Top