I have a DataView, called DataView1, that is showing the data from a table called INFO. A DetailsView is attached to this DataView.
When I click the Select link on a record for DataView1, I want the value of a certain field of DataView one to be put into the Select query of DataView2.
The reason being is this.
DataView1 contains the data for my INFO table.
DataView2 contains the data for my FILES table.
INFO can have many FILES.
Files can only have one INFO.
So when I click the Select link on a record on my DataView1(INFO table), I want only the files associated with the record to show up in DataView2(FILES table.)
Sorry if I am confusing.
How would I do this?
![]() |
0 |
![]() |
Hello.
well, i think that you can do that by using the new data source controls and parameters.
--
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
![]() |
0 |
![]() |
Thanks for the reply.
Do you have any examples?Here is my code that I have so far. Notice my select statement for DataView2. Where the question marks are is where I don't know what to put.
<
asp:GridView ID="GridView1" AllowSorting="True" AllowPaging="True" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="info_id" AutoGenerateColumns="False" Width="500px" SelectedIndex="0" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnPageIndexChanged="GridView1_PageIndexChanged" OnRowDeleted="GridView1_RowDeleted" OnSorted="GridView1_Sorted" > <Columns> <asp:CommandField ShowSelectButton="true" ShowDeleteButton="true" /> <asp:BoundField DataField="info_id" HeaderText="info_id" ReadOnly="True" SortExpression="info_id" /> <asp:BoundField DataField="class_name" HeaderText="class_name" ReadOnly="True" SortExpression="class_name" /> <asp:BoundField DataField="info_date" HeaderText="info_date" SortExpression="info_date" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=LAPTOP;Initial Catalog=classes;Persist Security Info=True;User ID=jettman26;Password=jettmanou812" SelectCommand="SELECT * FROM [info]" DeleteCommand="DELETE FROM [info] WHERE [info_id] = @original_info_id" ProviderName="System.Data.SqlClient"> </asp:SqlDataSource> </td> <td valign="top"> <asp:DetailsView AutoGenerateRows="False" DataKeyNames="info_id" DataSourceID="SqlDataSource3" HeaderText="Info Details" ID="DetailsView1" runat="server" Width="700px" OnItemUpdated="DetailsView1_ItemUpdated" OnItemInserted="DetailsView1_ItemInserted" > <Fields> <asp:BoundField DataField="info_id" HeaderText="info_id" ReadOnly="True" SortExpression="info_id" /> <asp:TemplateField HeaderText="class_name" SortExpression="class_name"><
EditItemTemplate><
asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"DataTextField
="class_name" DataValueField="class_name" SelectedValue='<%# Bind("class_name") %>'></
asp:DropDownList></
EditItemTemplate><
InsertItemTemplate><
asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"DataTextField
="class_name" DataValueField="class_name" SelectedValue='<%# Bind("class_name") %>'></
asp:DropDownList></
InsertItemTemplate><
ItemTemplate><
asp:Label ID="Label1" runat="server" Text='<%# Bind("class_name") %>'></asp:Label></
ItemTemplate></
asp:TemplateField> <asp:TemplateField HeaderText="info_date" SortExpression="info_date"><
EditItemTemplate><
asp:Calendar ID="Calendar1" runat="server" VisibleDate='<%# Bind("info_date") %>' SelectedDate='<%# Bind("info_date") %>'></
asp:Calendar></
EditItemTemplate><
InsertItemTemplate><
asp:Calendar ID="Calendar1" runat="server" ></
asp:Calendar></
InsertItemTemplate><
ItemTemplate><
asp:Label ID="Label2" runat="server" Text='<%# Bind("info_date") %>'></asp:Label></
ItemTemplate></
asp:TemplateField> <asp:BoundField DataField="notes" HeaderText="notes" SortExpression="notes" /> <asp:CommandField ShowEditButton="True" ShowInsertButton="True" /> </Fields> </asp:DetailsView> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:classesConnectionString %>" SelectCommand="SELECT DISTINCT [class_name] FROM [classes]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="Data Source=LAPTOP;Initial Catalog=classes;Persist Security Info=True;User ID=jettman26;Password=jettmanou812" SelectCommand="SELECT [info_id], [class_name], [info_date], [notes] FROM [info] WHERE ([info_id] = @info_id)" UpdateCommand="UPDATE [info] SET [class_name] = @class_name, [info_date] = @info_date, [notes] = @notes WHERE [info_id] = @original_info_id" InsertCommand="INSERT INTO [info] ([class_name], [info_date], [notes]) VALUES (@class_name, @info_date, @notes)" ProviderName="System.Data.SqlClient"> <SelectParameters> <asp:ControlParameter ControlID="GridView1" Name="info_id" PropertyName="SelectedValue" Type="String" /> </SelectParameters> <UpdateParameters> <asp:Parameter Name="info_date" Type="String" /> <asp:Parameter Name="notes" Type="String" /> <asp:Parameter Name="original_info_id" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="class_name" Type="String" /> <asp:Parameter Name="info_date" Type="String" /> <asp:Parameter Name="notes" Type="String" /> </InsertParameters> </asp:SqlDataSource> </td> </tr> <tr> <td valign="top"> <asp:GridView ID="GridView2" AllowSorting="True" AllowPaging="True" runat="server" DataSourceID="SqlDataSource4" DataKeyNames="file_id" AutoGenerateColumns="False" Width="500px" SelectedIndex="0" > <Columns> <asp:ButtonField Text="Download" CommandName="Download"/> <asp:CommandField ShowDeleteButton="True" /> <asp:BoundField DataField="file_name" HeaderText="file_name" ReadOnly="True" SortExpression="file_name" /> <asp:BoundField DataField="file_size" HeaderText="file_size" SortExpression="file_size" /> <asp:BoundField DataField="file_path" HeaderText="file_path" SortExpression="file_path" /> <asp:BoundField DataField="upload_date" HeaderText="upload_date" SortExpression="upload_date" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="Data Source=LAPTOP;Initial Catalog=classes;Persist Security Info=True;User ID=jettman26;Password=jettmanou812" SelectCommand="SELECT [Files.file_id], [Files.info_id], [Files.file_name], [Files.file_path] FROM [files] INNER JOIN [Info] ON [Files.info_id] = [Info.info_id] AND [Files.info_id] = [Info.info_id] WHERE [Files.info_id] = ??????????????? DeleteCommand="DELETE FROM [files] WHERE [file_id] = @original_file_id" ProviderName="System.Data.SqlClient"> </asp:SqlDataSource> </td> </tr>
![]() |
0 |
![]() |
Luis Abreu wrote:
Hello.
well, i think that you can do that by using the new data source controls and parameters.
Luis Abreu,
I figured it out. You pointed me in the right direction. Thanks!
![]() |
0 |
![]() |
Hi,
Detailview or Gridview cannot contain LIST controls in its EditItemTemplate,
Mabey you can search the reason in this forums.
![]() |
0 |
![]() |