467,222 Members | 1,416 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,222 developers. It's quick & easy.

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 OldValuesParameterFormatString and
ConflictDetection in the sqlSatasource. Any ideas.? Source below.

Thanks

<%@ Page Language="VB" ContentType="text/html"
ResponseEncoding="iso-8859-1" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled 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" AutoGenerateColumns="false"
runat="server" DataKeyIds="OrderID,AmazonID" DataSourceId="srcOrders"
CssClass="grid" autogenerateeditbutton="true" GridLines="Horizontal">

<Columns>

<asp:Boundfield DataField = "OrderID" HeaderText="OrderID"
readonly="true"/>

<asp:TemplateField HeaderText="IT Buy Address">
<ItemTemplate>
<%# Eval("add1") & "<br/>" & Eval("add2") & "<br/>" & Eval("add3")
& "<br/>" & Eval("city") & "<br/><strong>" & Eval("postcode") & "</
strong>" %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amazon Address">
<ItemTemplate>
<%# Eval("AOshipadd1") & "<br/>" & Eval("AOshipadd2") & "<br/>" &
Eval("AOshipadd3") & "<br/>" & Eval("AOshipcity") & "<br/><strong>" &
Eval("AOshippostcode") & "</strong>" %>
</ItemTemplate>

<edititemtemplate>

<asp:TextBox
id="AOshipadd1"
text='<%# Bind("AOshipadd1")%>'
runat="server" />
<asp:TextBox
id="AOshipadd2"
text='<%# Bind("AOshipadd2")%>'
runat="server" />
<asp:TextBox
id="AOshipadd3"
text='<%# Bind("AOshipadd3")%>'
runat="server" />
<asp:TextBox
id="AOshipcity"
text='<%# Bind("AOshipcity")%>'
runat="server" />
<asp:TextBox
id="AOshippostcode"
text='<%# Bind("AOshippostcode")%>'
runat="server" />
</edititemtemplate>
</asp:TemplateField>

<asp:Boundfield DataField = "ParcelNum" HeaderText="City Link ID" /
>

</Columns>

</asp:GridView>
<asp:SqlDataSource
id="srcOrders"
ConnectionString="MYConnString"

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

</body>
</html>

May 16 '07 #1
  • viewed: 1354
Share:
7 Replies
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*********@googlemail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.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 OldValuesParameterFormatString and
ConflictDetection in the sqlSatasource. Any ideas.? Source below.

Thanks

<%@ Page Language="VB" ContentType="text/html"
ResponseEncoding="iso-8859-1" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled 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" AutoGenerateColumns="false"
runat="server" DataKeyIds="OrderID,AmazonID" DataSourceId="srcOrders"
CssClass="grid" autogenerateeditbutton="true" GridLines="Horizontal">

<Columns>

<asp:Boundfield DataField = "OrderID" HeaderText="OrderID"
readonly="true"/>

<asp:TemplateField HeaderText="IT Buy Address">
<ItemTemplate>
<%# Eval("add1") & "<br/>" & Eval("add2") & "<br/>" & Eval("add3")
& "<br/>" & Eval("city") & "<br/><strong>" & Eval("postcode") & "</
strong>" %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amazon Address">
<ItemTemplate>
<%# Eval("AOshipadd1") & "<br/>" & Eval("AOshipadd2") & "<br/>" &
Eval("AOshipadd3") & "<br/>" & Eval("AOshipcity") & "<br/><strong>" &
Eval("AOshippostcode") & "</strong>" %>
</ItemTemplate>

<edititemtemplate>

<asp:TextBox
id="AOshipadd1"
text='<%# Bind("AOshipadd1")%>'
runat="server" />
<asp:TextBox
id="AOshipadd2"
text='<%# Bind("AOshipadd2")%>'
runat="server" />
<asp:TextBox
id="AOshipadd3"
text='<%# Bind("AOshipadd3")%>'
runat="server" />
<asp:TextBox
id="AOshipcity"
text='<%# Bind("AOshipcity")%>'
runat="server" />
<asp:TextBox
id="AOshippostcode"
text='<%# Bind("AOshippostcode")%>'
runat="server" />
</edititemtemplate>
</asp:TemplateField>

<asp:Boundfield DataField = "ParcelNum" HeaderText="City Link ID" /
>>


</Columns>

</asp:GridView>
<asp:SqlDataSource
id="srcOrders"
ConnectionString="MYConnString"

SelectCommand="Select * from Orders"
UpdateCommand="UPDATE ORders SET ParcelNum = @Parcelnum Where (OrderID
= @OrderID); UPDATE OTHER_ORDER_REPORT 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*********@googlemail.comwrote in message
news:11**********************@u30g2000hsc.googlegr oups.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*********@googlemail.comwrote in message
news:11**********************@u30g2000hsc.googlegr oups.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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Newbie | last post: by
1 post views Thread by jason@cyberpine.com | last post: by
6 posts views Thread by Doug Bell | last post: by
reply views Thread by RolfHerbert@googlemail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.