473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

GridView DataKey

I posted this earlier, and got no response. Basically I need to be able to
grab a value from one of the fields in a gridView to populate a dropdown in
another column of the gridview:
I have a gridView that has 2 templated columns that contain drop-down lists.
The first drop down list uses a value off of a formview on the same page for
filtering. The 2nd drop-down is supposed to use the value off the first
drop-down for it's parameter. I tried to add a parameter definition the
same way I did referring to the FormView, but I get the following error:

DataBinding: 'System.Web.UI.WebControls.GridView' does not contain a
property with the name 'DataKey'.

Offending Code:
<asp:ObjectDataSource ID="dsTarget" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetTargetsForSite" TypeName="AL.clsSite">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="SiteID"
PropertyName="DataKey(&quot;SiteID&quot;)" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

wheras this code works:

<asp:ObjectDataSource ID="dsSite" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetSitesForPublisher" TypeName="AL.clsSite">
<SelectParameters>
<asp:ControlParameter ControlID="FormView1" Name="PublisherID"
PropertyName="DataKey(&quot;PublisherID&quot;)" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

So, first, is this the best way to get a value out of a formView ? 2nd, how
do I get a value from the GridView ?

Thanks,

Mark Richards
Dec 16 '05 #1
1 8281
Hi Mark,

As the message indicated, there is no property on the GridView named
"DataKey" whereas there is a "DataKey" property on the FormView. The
GridView has a collection for the DataKeys
http://msdn2.microsoft.com/en-us/lib....datakeys.aspx

On the GridView you may use the SelectedDataKey.Values[i] (where i is the
index of the key) as I did in this demo:
http://www.webswapp.com/CodeSamples/...idView_1c.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Mark Richards" wrote:
I posted this earlier, and got no response. Basically I need to be able to
grab a value from one of the fields in a gridView to populate a dropdown in
another column of the gridview:
I have a gridView that has 2 templated columns that contain drop-down lists.
The first drop down list uses a value off of a formview on the same page for
filtering. The 2nd drop-down is supposed to use the value off the first
drop-down for it's parameter. I tried to add a parameter definition the
same way I did referring to the FormView, but I get the following error:

DataBinding: 'System.Web.UI.WebControls.GridView' does not contain a
property with the name 'DataKey'.

Offending Code:
<asp:ObjectDataSource ID="dsTarget" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetTargetsForSite" TypeName="AL.clsSite">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="SiteID"
PropertyName="DataKey("SiteID")" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

wheras this code works:

<asp:ObjectDataSource ID="dsSite" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetSitesForPublisher" TypeName="AL.clsSite">
<SelectParameters>
<asp:ControlParameter ControlID="FormView1" Name="PublisherID"
PropertyName="DataKey("PublisherID")" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

So, first, is this the best way to get a value out of a formView ? 2nd, how
do I get a value from the GridView ?

Thanks,

Mark Richards

Dec 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mike | last post by:
i'd like to get datakey of GridView So i write code like below but it wasn't work well. how should i do? protected void BookGridView_RowDataBound(object sender, GridViewRowEventArgs e) { int...
0
by: Mark Richards | last post by:
I have a gridView that has 2 templated columns that contain drop-down lists. The first drop down list uses a value off of a formview on the same page for filtering. The 2nd drop-down is supposed to...
5
by: NH | last post by:
How do I find out the row index selected in the gridveiw row command method? I have an imageButton in a gridview cell and its corresponding code in the row command method needs to know the row...
1
by: Steven Blair | last post by:
Here is my problem: I have a GridView with a Select column. Once the user clicks the Select button the following things need to happen. 1. Need to store the DataKey of the selectedindex 2....
1
by: ram_kri | last post by:
Hi Guys, Here is a uncommon scenario that I had to work on.. I have a GridView which is associated to a DataSource. But I have a couple of columns (item-templates while the rest of the columns...
3
by: denvercr | last post by:
Hi how do i possibly get the value of a hidden column (id) of a gridview binded in sqldatasource? i have this code in C# usng GridViewRow and DataKey Classes to retrieve it, I also set the...
0
by: VB Programmer | last post by:
From the research I've done, when you are using a gridview and want to programatically refer to a column that is hidden you have to add it to the datakey of the gridview. I've done that for 2 of...
7
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
Is there a way to use a gridview in a timecard application, and if so, how? I was looking at using a gridview to display a person's hours worked in a week. To do this, many different data records...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview control with a template column that has a textbox and when the control is bound to the datasource the textbox is filled ok. I then change what is in the textbox in the gridview...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.