(master/detail) control using gridview and formview controls problem...

hi guys,

 i'm new to .net programming and have been toying with the (master/detail) control using gridview and formview controls...however, i can't seem to drilldown to the correct record when the primary key is a composite key. please help....

 

  <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>

0
yixiang
1/28/2008 11:07:36 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

7 Replies
1482 Views

Similar Articles

[PageSpeed] 46

Hi, and welcome to ASP.NET Forums!

Check this article http://www.asp.net/learn/data-access/tutorial-10-cs.aspx

Thanks

-Mark post(s) as "Answer" that helped you


Mark post(s) as "Answer" that helped you

Electronic Screw
Website||Blog||Dub@i.net
0
e_screw
1/28/2008 12:11:10 PM
In your WHERE clause, try 
(ServiceID = @ServiceID AND VersionNum = @VersionNum)
 

Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
1/28/2008 12:15:21 PM
Additionally, change your ControlParameter statements:
<asp:ControlParameter ControlID="GridView1" Name="ServiceID" PropertyName="SelectedDataKey.Values[0]" />
<asp:ControlParameter ControlID="GridView1" Name="VersionNum" PropertyName="SelectedDataKey.Values[1]" /> 
 

Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
1/28/2008 12:23:00 PM

hi all, thanks for the tips.

 However, problem is solved partialy.

 I am able to do insert and delete of records.

 However, I am still unable to do updates of records!

please help!

 Codes are below:

*i'm using oledb connnection*

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="ServiceID,VersionNo">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="ServiceID" HeaderText="ServiceID" SortExpression="ServiceID" />
            <asp:BoundField DataField="VersionNo" HeaderText="VersionNo" SortExpression="VersionNo" />
            <asp:BoundField DataField="ProviderName" HeaderText="ProviderName" SortExpression="ProviderName" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT [ServiceID], [VersionNo], [ProviderName], FROM [w_ServiceProvider] ORDER BY [ServiceID]">
    </asp:SqlDataSource>
    <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource2" Width="619px" CellPadding="4" DataKeyNames="ServiceID,VersionNo" ForeColor="#333333">
        <EditItemTemplate>
            ServiceID:
            <asp:TextBox ID="ServiceIDTextBox" runat="server" Text='<%# Bind("ServiceID")%>'></asp:TextBox><br />
            VersionNo:
            <asp:TextBox ID="VersionNoTextBox" runat="server" Text='<%# Bind("VersionNo") %>' ></asp:TextBox><br />
            ProviderName:
            <asp:TextBox ID="ProviderNameTextBox" runat="server" Text='<%# Bind("ProviderName") %>'></asp:TextBox><br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update">
            </asp:LinkButton>
            <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel">
            </asp:LinkButton>
        </EditItemTemplate>
        <InsertItemTemplate>
            ServiceID:
            <asp:TextBox ID="ServiceIDTextBox" runat="server" Text='<%# Bind("ServiceID") %>'>
            </asp:TextBox><br />
            VersionNo:
            <asp:TextBox ID="VersionNoTextBox" runat="server" Text='<%# Bind("VersionNo") %>'>
            </asp:TextBox><br />
            ProviderName:
            <asp:TextBox ID="ProviderNameTextBox" runat="server" Text='<%# Bind("ProviderName") %>'>
            </asp:TextBox><br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insert">
            </asp:LinkButton>
            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel">
            </asp:LinkButton>
        </InsertItemTemplate>
        <ItemTemplate>
            ServiceID:
            <asp:Label ID="ServiceIDLabel" runat="server" Text='<%# Bind("ServiceID") %>'></asp:Label><br />
            VersionNo:
            <asp:Label ID="VersionNoLabel" runat="server" Text='<%# Bind("VersionNo") %>'></asp:Label><br />
            ProviderName:
            <asp:Label ID="ProviderNameLabel" runat="server" Text='<%# Bind("ProviderName") %>'>
            </asp:Label><br />
            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                Text="Edit">
            </asp:LinkButton>
            <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                Text="Delete">
            </asp:LinkButton>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                Text="New">
            </asp:LinkButton>
        </ItemTemplate>
    </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"        
        SelectCommand="SELECT ServiceID, VersionNo, ProviderName Remarks FROM w_ServiceProvider WHERE (ServiceID=? AND VersionNo=?)"
          InsertCommand="INSERT INTO dbo.w_ServiceProvider(ServiceID, VersionNo, ProviderName) VALUES (?,?,?,?,?,?,?,?)"
        DeleteCommand="DELETE FROM [w_ServiceProvider] WHERE ([ServiceID] = ? AND [VersionNo] = ?)"
        UpdateCommand="UPDATE [w_ServiceProvider] SET ServiceID=?, VersionNo=?, ProviderName =?, WHERE (ServiceID=?) AND (VersionNo=?)"
        >
        <SelectParameters>
            <asp:ControlParameter ControlID="GridView1" Name="?" PropertyName="SelectedDataKey.Values[0]" />
            <asp:ControlParameter ControlID="GridView1" Name="?" PropertyName="SelectedDataKey.Values[1]" />
        </SelectParameters>  
        <UpdateParameters>
           <asp:ControlParameter ControlID="GridView1" Name="?" PropertyName="SelectedDataKey.Values[0]" />
            <asp:ControlParameter ControlID="GridView1" Name="?" PropertyName="SelectedDataKey.Values[1]" />
         </UpdateParameters>    
        <DeleteParameters>
             <asp:ControlParameter ControlID="GridView1" Name="?" PropertyName="SelectedDataKey.Values[0]" />
            <asp:ControlParameter ControlID="GridView1" Name="?" PropertyName="SelectedDataKey.Values[1]" />
        </DeleteParameters>
    </asp:SqlDataSource>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentData1" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="contentFooter" Runat="Server">
</asp:Content>

 

0
yixiang
1/29/2008 1:56:19 AM

Hi:

  Please remove this and try again:

        <UpdateParameters>
           <asp:ControlParameter ControlID="GridView1" Name="?" PropertyName="SelectedDataKey.Values[0]" />
            <asp:ControlParameter ControlID="GridView1" Name="?" PropertyName="SelectedDataKey.Values[1]" />
         </UpdateParameters>  

  Actually you just need SelectParameters that points to the SelectedDataKey of GridView. Others are unnecessary.

Regards


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
1/30/2008 7:52:31 AM

 Hi everyone thanks for all your tips!

 

i've finally solved it!

 

now i'm trying to connect to an ORACLE 10g database using the same setup..

 the select and add new record function is working...but not the edit or delete function...

 

please help...

    <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="IPADDRESS" AutoGenerateColumns="False">
        <Columns>
 ...

      </Columns>
    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:OracleConnectionString %>"
        ProviderName="<%$ ConnectionStrings:OracleConnectionString.ProviderName %>" SelectCommand='SELECT IPADDRESS FROM ENVIRONMENT'>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:OracleConnectionString %>"
    DeleteCommand="DELETE FROM ENVIRONMENT WHERE (IPADDRESS = :IPADDRESS)"
    InsertCommand="INSERT INTO ENVIRONMENT(IPADDRESS) VALUES (:IPADDRESS)"
    ProviderName="<%$ ConnectionStrings:OracleConnectionString.ProviderName %>"
    SelectCommand="SELECT IPADDRESS FROM ENVIRONMENT WHERE (IPADDRESS = :IPADDRESS)"
    UpdateCommand="UPDATE ENVIRONMENT SET IPADDRESS =:IPADDRESS WHERE (IPADDRESS = :IPADDRESS)"            ConflictDetection="CompareAllValues" OldValuesParameterFormatString="original_{0}">
        <DeleteParameters>
            <asp:Parameter Name="IPADDRESS" Type="String"  />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="IPADDRESS" />
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="GridView1" Name="IPADDRESS" PropertyName="SelectedValue"  Type="String"/>
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter Name="IPADDRESS" />
        </InsertParameters>
    </asp:SqlDataSource>

    <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource2">
    </asp:FormView>

0
yixiang
1/30/2008 8:26:58 AM

Hi:

 

yixiang:
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource2">
    </asp:FormView>

 

  The FormView is empty?

  As to delete you can set DataKeyNames for FormView. As to update you'd better paste the correct template of FormView so that we can see what's wrong.

Thanks


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
1/30/2008 8:37:53 AM
Reply:

Similar Artilces:

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

Problem Using Slider Control in Gridview Control
Hello to all,   it is urgent.   i want to use slider control in a Gridview Template Column, if someone can help me how i can get this functionality?...

using controlS to control a gridview
This question is probably posted but i did not bother to look at 10,000+ posts so i am sorry. I've seen the tutorial where he builds a dataset and uses a gridview and controls the gridview with the drop down list box. What i am trying to do is to control the gridview with 2 drop down list boxes. First select the Country you life in and then the State. I've looked at the grid view properties but couldn't find where i can add another parameter. Is it possible to control a grid view (or any form of displaying the information) with more than 1 controller? Thank You.  ...

What control do I use (or do I not use a control at all...)
Okay so here's the story so far. I am making a blog to be incorporated into a website. Well, I'm doing the blog from scratch. I'm using MySQL to source all the data via MySQL .NET/Connector. Now while developing the script, I used DataReader and Response.Write to show the blog topics. Now that it has come to put it under a design (I'm using a Master Page for that), I've hit the problem. Response.Write shows all the topics before any of the design elements could be incorporated. So that (more or less) is out of question. So next I looked into the data presentation controls. I looked up GridVi...

Looking for a beginners tutorial or guide on using GRIDVIEW control with FORMVIEW control
what i want to be able to do is add a gridview control onto the page.. have it display my results then have a link to take me to another page where they can edit the data if needed I have a current project im working on that i have a search function on the top part and that value us passed into the GRIDVIEW below it and displays records.. each of those records has a link to a edit page.. since the gridview is merely a small teaser of all the data for the records.. the next page will display ALL fields for that record within a FORMVIEW.. The itemtemplate displays all the data in a nice fo...

Cascading Dropdown error in formview controls and finding all controls in formview controls
can help with the following? Instantiate Cascading Dropdowns within Formview controls (this returns the error message "databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control".) Pass values between controls within master controls such as Textboxes within formviews (example: Pass the selected value in a dropdownlist to another textbox both WITHIN a formview control) Expose the public properties of a master page Hi arraybiz, 1) I need your code. See sample: http://www.mikepope.com/blog/fun/cascadingdropdowns_dy...

Control in control problems
************* Edited by moderator Adec *************** Inserted missing < code></ code> tags. Always include such tags when including code in your postings. Many readers disregard postings without the code tags. ************************************************** Here is the senario I am presented with. I will follow it with the code. Webform 1 contains User Control 1. Now, this control contains User Control 2. I have Webform 1 call a subroutine 1 in User Control 1. This sub routine, calls a subroutine 2 in User control 2. Unfortunately, VS2003 will not allow Use...

Control In Control Problem
Hi, guys.I've written two web controls for reservation system.One is a Datepicker which alows user to pick a date (pretty obvious ) and another one is a Reservation which alows user to pick a location (hotel) and number of rooms and number of people in each room.Both of them inherit WebControl and implement ICallbackEventHandler and INamingContainerI bind to them list with available days... List of hotels and regions (if it's to be used for reservation in hotels chain) well... whatever...Both of them work great while I don't try to include the DatePicker in the Reservation... Her...

Using Validation controls with FormView control
Hello dears; Is  it possible to use validation controls with FormView or DetailsView controls during Edit mode? Such controls have no Error Events handlers to use and there textboxes have only TextChanged Event handlers which have no text property. Also how can i get the content of a cell in theFormView ? Thanks alot  VWD2005 The FormView control supports templates -- so you could add an ItemTemplate or EditTemplate to it, and absolutely put validation controls within there as well. Hope this helps, Scott Thanks Scott  VWD2005 Hello I know your busy but I can'...

how to use validation controls on FormView control?
Hi all,  I searched the forum for a solution to my problem, but while many of you seem to have had similar problems, I couldn't solve my (I thought easy) problem. This is my setup: I try to put a FormView control on my page where users can insert records into a database. All good, except that I want to add some Validation controls to my form, at least some RequiredField validators. I tried adding the controls in the InsertItem Template for starters, but that doesn't seem to work:" Unable to find control id 'FirstNameTextBox' referenced by the 'ControlT...

Problem in Using DropDownList Control to select a selected row of SqlDataSource that is under GridView Control
Hi all,In my SQL Server Management Studio Express, I have a database "ChemDatabase" that has a table "LabData"  formatted in the following way: SampleID int PRIMARY KEY, SampleName nvarchar(25), ChemicalName, nvarchar(25), Concentration decimal(6.2) with 5 rows of records in this .dbo table. In my Visual Web Developer Express, I created a website "RPD-TCE" for extracting a row of record from the LabData table by using a DropDownList, a GridView and a SqlDataSource.  I want to click DropDownList to list one number of S...

Getting the control id of a control inside gridview control
 uhmm.. a little bit confusing regarding my subject because i dont know how to say it...by the way my problem is how can i get the id of a control (e.g. textbox) inside the gridview... and the textbox is in the templatefield... is there any way i can get its id??  hoping i could get a reply as soon as possible... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) What do you want's to do by getting the id of the Text box? Do you want's to find particular Textbox with certain id ? Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MC...

trouble with master grid controling detail formview and detail gridview
I have two tables, temp and photo.  Temp contains an a number of fields including ID, and sessionID.  ID is an identity field and a primary key.  Photo contains a number of fields including sessionID, which is neither an identity field nor a primary key.All my datasources are linqdatasources.Gridview1 displays a subset of the temp table.  Formview1 displays all the fields in temp where ID == @ID.  So far so good.  Gridview2 displays some of the fields in photo where sessionID == @sessionID.  Gridview2 always comes up empty.I tried looking for the record whe...

Master/Detail Form using Gridview and Details View controls
There are useful codes in the following page: Introducing the ASP.NET 2.0 GridView and DetailsView Controlshttp://msdn.microsoft.com/vbasic/reference/ASP.NET/default.aspx?pull=/library/en-us/dnvs05/html/grddetview.aspI used code under Listing 12. Creating a Master/Detail Form and everything worked fine. But when I clicked the master record to view the details I am getting a server error message "Cannot find column [@EmployeeID]" Where did I go wrong? Can anybody clarify?...

Web resources about - (master/detail) control using gridview and formview controls problem... - asp.net.presentation-controls

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 1/21/2016 6:56:23 PM