473,761 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid readonly or non visible data not passed back

Hi all,

Source code below. I am using an sqldatasorce to populate a datagrid.
I am using datakeyIds.

I am interested in two keys which I have added to the datakeyids,
however if either of the keys is not databound, set to visible=false
or readonly=true, they are unavailable as parameters in my update
statement.

Any ideas how/why this happens and how to get arround it..?

Thanks

Source...
Wrox Home

View Cart | My Account
Support | Contact Us
Search P2P for Advanced
Search

Members:
Participate in discussions or edit your profile.

Login:
Password:

Remember Me
Forgot Your Password?

New Users: Register Now

Forum Tools
View All Forums
View Active Topics
Archives
FAQ
Terms of Use

Get More Wrox For Less!

New Titles for ASP.NET
Professional Community Server
Professional Community Server

Professional ASP.NET 2.0 Databases
Professional ASP.NET 2.0 Databases

Wrox Programmers Reference Series - Learn tips and tricks from the
experts!

p2p.wrox.com Forums
P2P Forum ASP and ASP.NET ASP.NET 2.0 Beginner Missing
parameters in Datagrid .net 2
p2p Community Forums
Need to download code? View our list of code downloads.
New Topic Reply to Topic Printer Friendly
Author Previous Topic Topic Next Topic

kangarolf
Starting Member

1 Posts

Posted - 05/16/2007 : 07:24:56 AM Show Profile Reply with Quote
Hi all,

I have a problem in that in my datagrid any datakeys which are not
visible and editable in the datagrid (if the column visibility is set
to false or readonly is set to true) do not seem to be passed back to
the script and are unavailable as parameters for my updatecommand.

I have tried with and without OldValuesParame terFormatString and
ConflictDetecti on in the sqlSatasource. Any ideas.? Source below.

Thanks

<%@ Page Language="VB" ContentType="te xt/html"
ResponseEncodin g="iso-8859-1" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitl ed Document</title>
<style type="text/css">
..grid {width:550px; border:1px solid;}
..grid td {vertical-align: top; }
..grid th {background-color:#0099FF; color:#FFFFFF;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="grdOrders" AutoGenerateCol umns="false"
runat="server" DataKeyIds="Ord erID,AmazonID" DataSourceId="s rcOrders"
CssClass="grid" autogenerateedi tbutton="true" GridLines="Hori zontal">

<Columns>

<asp:Boundfie ld DataField = "OrderID" HeaderText="Ord erID"
readonly="true"/>

<asp:TemplateFi eld HeaderText="IT Buy Address">
<ItemTemplate >
<%# Eval("add1") & "<br/>" & Eval("add2") & "<br/>" & Eval("add3")
& "<br/>" & Eval("city") & "<br/><strong>" & Eval("postcode" ) & "</
strong>" %>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Ama zon Address">
<ItemTemplate >
<%# Eval("AOshipadd 1") & "<br/>" & Eval("AOshipadd 2") & "<br/>" &
Eval("AOshipadd 3") & "<br/>" & Eval("AOshipcit y") & "<br/><strong>" &
Eval("AOshippos tcode") & "</strong>" %>
</ItemTemplate>

<edititemtempla te>

<asp:TextBox
id="AOshipadd1 "
text='<%# Bind("AOshipadd 1")%>'
runat="server" />
<asp:TextBox
id="AOshipadd2 "
text='<%# Bind("AOshipadd 2")%>'
runat="server" />
<asp:TextBox
id="AOshipadd3 "
text='<%# Bind("AOshipadd 3")%>'
runat="server" />
<asp:TextBox
id="AOshipcity "
text='<%# Bind("AOshipcit y")%>'
runat="server" />
<asp:TextBox
id="AOshippostc ode"
text='<%# Bind("AOshippos tcode")%>'
runat="server" />
</edititemtemplat e>
</asp:TemplateFie ld>

<asp:Boundfie ld DataField = "ParcelNum" HeaderText="Cit y Link ID" /
>

</Columns>

</asp:GridView>
<asp:SqlDataSou rce
id="srcOrders"
ConnectionStrin g="MYConnString "

SelectCommand=" Select * from Orders"
UpdateCommand=" UPDATE ORders SET ParcelNum = @Parcelnum Where (OrderID
= @OrderID); UPDATE OTHER_ORDER_REP ORT Set [ship-address-1] =
@AOshipadd1 Where [order-id] = @AmazonID"
Runat="server" />
</div>
</form>

</body>
</html>

May 16 '07 #1
7 1594
Server controls with visible=true don't get rendered to the client and,
naturally, don't come back in postbacks. Leave visible=false and hide the
columns with css rule display:none.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<Ro*********@go oglemail.comwro te in message
news:11******** **************@ o5g2000hsb.goog legroups.com...
Hi all,

Source code below. I am using an sqldatasorce to populate a datagrid.
I am using datakeyIds.

I am interested in two keys which I have added to the datakeyids,
however if either of the keys is not databound, set to visible=false
or readonly=true, they are unavailable as parameters in my update
statement.

Any ideas how/why this happens and how to get arround it..?

Thanks

Source...
Wrox Home

View Cart | My Account
Support | Contact Us
Search P2P for Advanced
Search

Members:
Participate in discussions or edit your profile.

Login:
Password:

Remember Me
Forgot Your Password?

New Users: Register Now

Forum Tools
View All Forums
View Active Topics
Archives
FAQ
Terms of Use

Get More Wrox For Less!

New Titles for ASP.NET
Professional Community Server
Professional Community Server

Professional ASP.NET 2.0 Databases
Professional ASP.NET 2.0 Databases

Wrox Programmers Reference Series - Learn tips and tricks from the
experts!

p2p.wrox.com Forums
P2P Forum ASP and ASP.NET ASP.NET 2.0 Beginner Missing
parameters in Datagrid .net 2
p2p Community Forums
Need to download code? View our list of code downloads.
New Topic Reply to Topic Printer Friendly
Author Previous Topic Topic Next Topic

kangarolf
Starting Member

1 Posts

Posted - 05/16/2007 : 07:24:56 AM Show Profile Reply with Quote
Hi all,

I have a problem in that in my datagrid any datakeys which are not
visible and editable in the datagrid (if the column visibility is set
to false or readonly is set to true) do not seem to be passed back to
the script and are unavailable as parameters for my updatecommand.

I have tried with and without OldValuesParame terFormatString and
ConflictDetecti on in the sqlSatasource. Any ideas.? Source below.

Thanks

<%@ Page Language="VB" ContentType="te xt/html"
ResponseEncodin g="iso-8859-1" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitl ed Document</title>
<style type="text/css">
.grid {width:550px; border:1px solid;}
.grid td {vertical-align: top; }
.grid th {background-color:#0099FF; color:#FFFFFF;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="grdOrders" AutoGenerateCol umns="false"
runat="server" DataKeyIds="Ord erID,AmazonID" DataSourceId="s rcOrders"
CssClass="grid" autogenerateedi tbutton="true" GridLines="Hori zontal">

<Columns>

<asp:Boundfie ld DataField = "OrderID" HeaderText="Ord erID"
readonly="true"/>

<asp:TemplateFi eld HeaderText="IT Buy Address">
<ItemTemplate >
<%# Eval("add1") & "<br/>" & Eval("add2") & "<br/>" & Eval("add3")
& "<br/>" & Eval("city") & "<br/><strong>" & Eval("postcode" ) & "</
strong>" %>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Ama zon Address">
<ItemTemplate >
<%# Eval("AOshipadd 1") & "<br/>" & Eval("AOshipadd 2") & "<br/>" &
Eval("AOshipadd 3") & "<br/>" & Eval("AOshipcit y") & "<br/><strong>" &
Eval("AOshippos tcode") & "</strong>" %>
</ItemTemplate>

<edititemtempla te>

<asp:TextBox
id="AOshipadd1 "
text='<%# Bind("AOshipadd 1")%>'
runat="server" />
<asp:TextBox
id="AOshipadd2 "
text='<%# Bind("AOshipadd 2")%>'
runat="server" />
<asp:TextBox
id="AOshipadd3 "
text='<%# Bind("AOshipadd 3")%>'
runat="server" />
<asp:TextBox
id="AOshipcity "
text='<%# Bind("AOshipcit y")%>'
runat="server" />
<asp:TextBox
id="AOshippostc ode"
text='<%# Bind("AOshippos tcode")%>'
runat="server" />
</edititemtemplat e>
</asp:TemplateFie ld>

<asp:Boundfie ld DataField = "ParcelNum" HeaderText="Cit y Link ID" /
>>


</Columns>

</asp:GridView>
<asp:SqlDataSou rce
id="srcOrders"
ConnectionStrin g="MYConnString "

SelectCommand=" Select * from Orders"
UpdateCommand=" UPDATE ORders SET ParcelNum = @Parcelnum Where (OrderID
= @OrderID); UPDATE OTHER_ORDER_REP ORT Set [ship-address-1] =
@AOshipadd1 Where [order-id] = @AmazonID"
Runat="server" />
</div>
</form>

</body>
</html>

May 16 '07 #2
Thanks for the reponse..not really an adequate solution. I dont want
these data elements rendered anywhere even if 'hidden' by CSS. Ahy are
they not posted back if there are part of the DataKeyIds
declaration..? It also doesnt work if they are made visible but
READONLY.

Thank you

Rolf

May 16 '07 #3
Thanks for the response. It still doesnt explain why if the data is
part of the DataKeyIds declaration it is not available in the
postback. Also I may not want these data items rendered anywhere on
the page. 'Hiding' them with CSS is not an adequate solution, you
could simply turn off CSS and there they would be. Also it doesnt work
if the data is bound but marked as READONLY..still not posted back.

Thanks
Rolf

May 16 '07 #4
By any chance, do you mean DataKeyNames? Try changing DataKeyIds to
DataKeyNames and see if it works.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<Ro*********@go oglemail.comwro te in message
news:11******** **************@ u30g2000hsc.goo glegroups.com.. .
Thanks for the reponse..not really an adequate solution. I dont want
these data elements rendered anywhere even if 'hidden' by CSS. Ahy are
they not posted back if there are part of the DataKeyIds
declaration..? It also doesnt work if they are made visible but
READONLY.

Thank you

Rolf

May 16 '07 #5
Sorry thats a typo..its DataKeyNames... .and no it still doesnt work.

Thanks
May 16 '07 #6
The key fields value are kept in the ViewState. Do you have it enabled?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<Ro*********@go oglemail.comwro te in message
news:11******** **************@ u30g2000hsc.goo glegroups.com.. .
Sorry thats a typo..its DataKeyNames... .and no it still doesnt work.

Thanks


May 16 '07 #7
PROBLEM SOLVED

Hi there,

I have now solved this problem (bug or feature!) by going back through
and looking at examples and just slavishly changing anything that
looked different till it worked. The problem was my original query was
a join of three tables and it used table aliases. These messed up the
link between the DATAKEYNAMES and the column names somehow. I had to
include the SQL keyword AS to rename the column to its non-aliased
form.

So a query such as;
Select O.key, T.Productkey from Orders O Inner Join Transactions T ON
O.Key= T.ForeignKey

with DataKeyNames = "key,Productkey "

would fail, you have to reqrite the query as;
Select O.key AS key, T.Productkey as Productkey from Orders O Inner
Join Transactions T ON O.Key= T.ForeignKey

then the parameters are available for the updatecommand.

Thanks
Rolf

May 16 '07 #8

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

Similar topics

3
3030
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can download a fully working C# sample with the Northwind.mdb here: www.insightgis.com.au/web/stuff/DataGridCombo.zip
3
2101
by: Newbie | last post by:
I am using a Datagrid to show the contents of a DataTable. But it seems like the Datagrid is not getting the contents of the Datatable when the button ( btnAddAnotherLaborCategory) is clicked. private void Page_Load(object sender, System.EventArgs e) { DataTable dataTable; DataColumn dataColumn; DataRow dataRow; dataTable = new DataTable("ratesTable");
1
1540
by: jason | last post by:
The guts of the below asp.net vb code was pieced together from another thread - all due credit to it's original author. Thank you! I've modified it to maintain a small local Microsoft 2000 access DB via a datagrid control. The add and delete functions work great, but the edit does not actually update the database. I put in some displays and apparently on the first item in the grid gets set during editing, all others come back empty???
2
2023
by: jason | last post by:
Pardon my ignorance on this. The below code works, except, when I edit a record and update the two drop downs take the first entry in the dropdownlist if not selected. I'd also like the dropdown to show the current value in edit mode. I'm sure this is a common question. I've reviewed several related post and tried them out to no avial. Some of the offerings in listgroup look right on, but are not clear on where to handle the suggested...
5
2791
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go to the database to get the next page. Is there a way to use the dataset to allow us to read back and forth in it instead of going back to the database to get it? Thanks,
1
2692
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting, paginantion or accepting the add and remove item events. What i am observing is that none of the vents are happening... (Sort, page, or item). I am sure I am missing something basic here... Need help... Thanks much
1
2368
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .. http://sf-f.org, weblog and search engine for fans and writers of
6
2246
by: Doug Bell | last post by:
Hi I have a DataGrid with some hidden columns and also some read Only and some ComboBox Columns. Sandard Tabbing through the Datagrid sees the focus go to the hidden columns requiring further Tabbing to get to the desired column but it works fine stopping correctly on the ComboBox column. I have built a routine to test whether the use is Tabbing forward or back (Shift Tab) by looking at the last location, not by trapping the Keys. If
0
1158
by: RolfHerbert | last post by:
Hi all, I have a problem in that in my datagrid any datakeys which are not visible and editable in the datagrid (if the column visibility is set to false or readonly is set to true) do not seem to be passed back to the script and are unavailable as parameters for my updatecommand. I have tried with and without OldValuesParameterFormatString and ConflictDetection in the sqlSatasource. Any ideas.? Source below.
0
9522
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9948
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.