Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 5th, 2008, 04:12 AM
Registered User
 
Join Date: Oct 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can not Edit gridview having TemplateField

 Hi,

I have a gridview which is having a TemplateField with a checkbox.When I edit this field an erro is occured saying,"Could not find control 'chkPrimary' in ControlParameter 'Primary_Skill'."I am giving the code below..Plz help me...

  <asp:GridView id="gdSkills" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="Emp_code,Skill_Id" PageSize="15" AllowPaging="True" AutoGenerateColumns="False">
        <HeaderStyle CssClass="gridViewHeader" />
        <RowStyle CssClass="gridViewRowStyle" Wrap="False" Width="100%" />
        <AlternatingRowStyle CssClass="gridViewAlternative" Wrap="False" Width="100%" />
                 <Columns>
                  <asp:BoundField DataField="Skill_name" HeaderText="Skill" ReadOnly="True" />
                  <asp:BoundField DataField="No_Months" HeaderText="No of Months" />
                   <asp:TemplateField HeaderText="Primary">
                     <ItemTemplate>
                         <asp:CheckBox ID="chkPrimary" runat="server" Checked='<%# GetBoolean(Eval("Skill_Id"),Eval("Emp_code"))%>' />
                      </ItemTemplate>
                   </asp:TemplateField>
                   <asp:CommandField ShowEditButton= "True"/>
                   </Columns>
         </asp:GridView>
         <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ProviderName="System.Data.SqlClient"

                ConnectionString="<%$ ConnectionStrings:MyDatabase%>"


                SelectCommand="select ES.Skill_id,Skill_name,emp_code,No_Months,Primary_ Skill from Skill S
                               join Emp_skills ES on S.Skill_id=ES.Skill_id
                               where emp_code=@Emp_code order by Skill_name"
                UpdateCommand="update emp_Skills set No_Months=@No_Months,Primary_Skill=@Primary_Skill where Skill_id=@Skill_id AND EMP_CODE=@Emp_Code">
                  <SelectParameters>
                   <asp:SessionParameter Name="Emp_code" SessionField="Empcode" Type="String" />
                  </SelectParameters>
                  <UpdateParameters>
                      <asp:Parameter Name="No_Months" Type="Double" />
                      <asp:Parameter Name="Skill_id" Type="Int32" />
                      <asp:ControlParameter Name="Primary_Skill" ControlID="chkPrimary" />
                      <asp:SessionParameter Name="Emp_code" SessionField="Empcode" Type="String" />
                  </UpdateParameters>
         </asp:SqlDataSource>


Reply With Quote
  #2 (permalink)  
Old March 5th, 2008, 05:33 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Inside you <asp:TemplateField> you have an <ItemTemplate>. To make the template field editable I'd assume you'd also need a <EditItemTemplate>.

http://msdn2.microsoft.com/en-us/lib...mtemplate.aspx

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #3 (permalink)  
Old March 5th, 2008, 04:42 PM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'd think that it is not possible for SqlDataSource control to know the existence of chkPrimary control inside the GridView in this case. I mean there could be n+1 rows inside that GridView. Which CheckBox is the right one?

I would think the only way to solve this is to change that parameter a bit:

<asp:Parameter Name="Primary_Skill" Type="Boolean" />

And add Selecting event handler to SqlDataSource where you set the value for Primary_Skill parameter:

Code:
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
    e.Command.Parameters["Primary_Skill"].Value = ((CheckBox)gdSkills.Rows[...].Cells[3].Controls[1]).Checked;
}
Or I could be totally mistaken of course. Wouldn't be the first time :)
Reply With Quote
  #4 (permalink)  
Old March 5th, 2008, 06:11 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Yet again a simple google search provides multiple possible solutions:
http://geekswithblogs.net/azamsharp/.../27/89475.aspx

Please, always try a search google first beore posting.

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #5 (permalink)  
Old March 6th, 2008, 06:36 AM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Coolcoder2007 is talking about GridView. So the problem still persist that which row has the correct CheckBox.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Resolved] GridView TemplateField - get value snufse ASP.NET 2.0 Basics 25 July 29th, 2008 07:25 AM
GridView edit problem mike72 ASP.NET 2.0 Basics 8 January 3rd, 2007 07:59 PM
edit item in gridview al-hijjawi Visual Studio 2005 0 December 27th, 2006 03:20 PM
edit gridview anurag_ur ASP.NET 2.0 Basics 3 June 21st, 2006 03:21 AM
edit gridview anurag_ur ASP.NET 2.0 Basics 0 June 20th, 2006 07:57 AM



All times are GMT -4. The time now is 04:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.