473,414 Members | 1,667 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,414 software developers and data experts.

Can't get current record ID from DetailsView (ReadOnly)

I have a simple DetailsView in ReadOnly mode. I have paging enabled
because I need to show more than one record.

When user clicks next/prev page (PageIndexChanged event) I need to get
the current record ID (that is not one of the displayed fields, so
..Cell(x) won't work).

I expected DetailsView.SelectedValue to do the job but it doesn't (it's
always Nothing).

How can I solve this? My code follows.

1 %@ Page Language="VB" %>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5 <script runat="server">
6
7 Protected Sub DetailsView1_PageIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs)
8 TextBox1.Text = DetailsView1.SelectedValue & ""
9 End Sub
10 </script>
11
12 <html xmlns="http://www.w3.org/1999/xhtml" >
13 <head runat="server">
14 <title>Untitled Page</title>
15 </head>
16 <body>
17 <form id="form1" runat="server">
18 <div>
19 <asp:DetailsView ID="DetailsView1" runat="server"
AllowPaging="True" AutoGenerateRows="False"
20 DataKeyNames="DocumentID"
DataSourceID="SqlDataSource1"
21 OnPageIndexChanged="DetailsView1_PageIndexChanged"
DataMember="DefaultView">
22 <Fields>
23 <asp:BoundField DataField="Revision"
HeaderText="Revision" SortExpression="Revision" />
24 <asp:BoundField DataField="Date" HeaderText="Date"
SortExpression="Date" />
25 </Fields>
26 </asp:DetailsView>
27 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
28 SelectCommand="SELECT * FROM
[Documents]"></asp:SqlDataSource>
29 <br />
30 <asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox></div>
31 </form>
32 </body>
33 </html>

Apr 2 '06 #1
1 2156
I tend to use

protected void SomeEventHandler(object sender, SomeEventArgsClass e)
{
MyClass someObject = (MyDetailsView.DataItem as MyClass);
if(null == someObject)
{
// DetailsView.DataItem is not castable to MyClass - it might be
null, or my typing might be wrong
}
else
{
DoSomethingWith(someObject);
}
}

private void DoSomethingWith(MyClass someObject){}
You should also be able to use the value from the DataKeyName, but I
never quite managed to get that to work for reasons which elude me.

Apr 2 '06 #2

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

Similar topics

5
by: Mike P | last post by:
The default format for the DetailsView control is for there to be a row per field. Is it possible set it to show more than one column per row (see below)? ID ... Name ......
3
by: Jason | last post by:
Anyone know how to make the text wrap in a text box of a DetailsView?
2
by: Ben | last post by:
Hi, In the code-behind, i can refer to the dropdownlist defined in the aspx file with this (e.g.) dropdownlist1.sekectedvalue = ... but why can i not refer to the label defined in the...
1
by: Timothy H. Schilbach | last post by:
Hi Everyone, I am having a massive issue trying to get custom data into my DV. What I want to do is sooo simple: 1. I have a single DV on a page 2. I created my own template (see below) 3....
0
by: wardemon | last post by:
Hi All, I have a web structure like the following: Repeater GridView DetailView /Repeater The GridView's & the DetailView's Datasource is being changed dynamically on the Repeater's...
1
by: needhelp1 | last post by:
I have gridview with a detailsview below. When I click on 'New' in brings up the DetailsView for inserting. When I click on 'Edit' in does not brink up the DetailsView. What am I doing wrong? I...
3
by: =?Utf-8?B?TWlrZSBE?= | last post by:
I need to dynamically set the ReadOnly value in a BoundField in a DetailsView. The DetailsView is generated from a GridView selection and has both Edit and New buttons. I need to be able to set...
1
by: gsauns | last post by:
I have a DetailsView inside a ModalPopup (using the AJAX ModalPopupExtender). I would like the user to have the ability to change the DetailsView's mode within the ModalPopup. But whenever I...
2
by: bob | last post by:
Hi, the detailsview (default mode = insert) is used to introduce names into the database. I need in code-behind the introduced name. I tried this: <asp:DetailsView ID="DetailsView1"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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,...

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.