473,513 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need query value not displayed in DataGrid

I have a simple DataGrid that displays a list of characteristics and
allows you to edit a description for each characteristic. The query
that feeds this involves a join, as the characteristics and their
descriptions are in separate tables. The DataKeyField of the DataGrid
is set to the description ID, but I also need to be able to access the
characteristic ID in my update query (without displaying it in the
DataGrid). I haven't had much luck coming up with a solution (I'm
pretty new to .NET). Can anyone help?

Thanks!
Anna

Nov 19 '05 #1
1 1234
You have to turn off the automatic use of columns and build them by hand.
The grid Property sheet can help - but once you see how it is done, it is
just as easy to directly edit the HTML and bind only those fields you want
to display.

Keep the datasource in Session for postbacks.
When the page is posted back you can define which row in the datasource was
selected (if you have a button in each row) and then you can use that index
value to identify all the info about that row in your datasource and get the
right Characteristic ID.

e.g. Note: OnItemCommand="GetRowInfo" (this method must defined in your code
behind.)

<asp:datagrid id="dg1" runat="server" Width="95%"
HorizontalAlign="Center"
BackColor="White" CellPadding="4" AllowSorting="True"
AutoGenerateColumns="False" GridLines="None"
CellSpacing="2" AllowPaging="True" PageSize="20" EnableViewState="False"
OnItemCommand="GetRowInfo">
<AlternatingItemStyle Wrap="False"></AlternatingItemStyle>
<ItemStyle Wrap="False"></ItemStyle>
<PagerStyle NextPageText="Next" PrevPageText="Previous" Wrap="False"
Mode="NumericPages"></PagerStyle>
<Columns>
<asp:BoundColumn DataField="myName" SortExpression="myName"
HeaderText="My Name"></asp:BoundColumn>
<asp:BoundColumn DataField="sometext" SortExpression="sometext"
HeaderText="Active"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Choose Row">
<ItemTemplate>
<asp:imagebutton CommandName="btnEdit" id="btnEdit"
runat="server" ImageUrl="~/img/edit.gif" ToolTip="Edit"></asp:imagebutton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

Protected Sub GetRowInfo(ByVal source As Object, ByVal e As
DataGridCommandEventArgs)
'Grid paging/sorting causes this event to fire and e.Item.ItemIndex=-1
so we should avoid an error by coding for this case.
If e.Item.ItemIndex >= 0 Then

'get the index of the row in the grid (which is also the index for
your data source)
Dim mIndex As Integer = CType(source, DataGrid).PageSize *
CType(source, DataGrid).CurrentPageIndex + e.Item.ItemIndex

If e.CommandName = "btnEdit" Then
Session("myKey") = myList(mIndex).myKey
'the page below expects a value of myKey to be in Session since you
chose it from the page with the grid.
Response.Redirect("~/MyEditPage.aspx")
End If

End If

End Sub

--
Joe Fallon

"Anna" <BC*****@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
I have a simple DataGrid that displays a list of characteristics and
allows you to edit a description for each characteristic. The query
that feeds this involves a join, as the characteristics and their
descriptions are in separate tables. The DataKeyField of the DataGrid
is set to the description ID, but I also need to be able to access the
characteristic ID in my update query (without displaying it in the
DataGrid). I haven't had much luck coming up with a solution (I'm
pretty new to .NET). Can anyone help?

Thanks!
Anna

Nov 19 '05 #2

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

Similar topics

3
5372
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says there is a sample file called Ixtrasp.asp, but I could not find it in my system although I installed indexing service. I followed the steps in MSDN...
0
1744
by: msnews | last post by:
Hi -- I'm very, very new to ASP.Net, and I've been trying for several days to figure out how to update a datagrid AND refresh it on the client side so that the page doesn't refresh. I've torn my code apart over and over each time I tried what I thought would be the code that would solve my problem. Maybe I'm going down the completely...
4
4086
by: Anna | last post by:
Hi all, I have a query in ASP.NET that selects text from a memo field in Access (among other things). The query appears to be truncating the text at 255 characters. I've done a little research on this and found some other Google Groups threads that were helpful, but I still don't have a solution. My query is rather complicated and uses a...
2
2911
by: Carl Howarth | last post by:
Hi, I have a datagrid being populated using an sqldatareader. One of the columns returns a bit value which currently gets displayed as 'True' or 'False'. I would like to be able to display an image of a tick when this value is true, and have placed an asp.net image control within the relevant template column. I presume I can achieve...
2
1162
by: student | last post by:
Hi all, I'm having trouble with my datagrid, it is suppose to display a row from a table called "Calls" based on what is selected in the dropdownlist which displays the first and last name from another table called "Contacts". The problem is only the dropdownlist is showing in the browser and nothing from the datagrid shows. Could someone...
3
1864
by: Larry Woods | last post by:
I have a datagrid that is carrying all fields of a record...except one. Now I want to update the underlying database via a dataadapter. The update is working but the field that is "left out" is not there, of course. How do I get that field back into the datatable for the database update? TIA, Larry Woods
0
1919
by: Matt | last post by:
I derived my own custom class from the datagrid class. I overrode the ProcessCmdKey Function, like this, to catch the up and down arrow keys: ====== Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean Const WM_KEYDOWN As Integer = &H100
0
2236
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional assistance. I say additional because I've already had help which is greatly appreciated. I do try to take the time and understand the provided script...
0
1169
by: Vagabond Software | last post by:
I am fairly new to ASP.NET, so bear with me... I have a Datagrid with a data-bound DropDownList in the TemplateColumn. Here is the HTML code: <asp:TemplateColumn HeaderText="Void"> <ItemStyle horizontalalign="Left" wrap="False"></ItemStyle> <ItemTemplate> <%#Databinder.Eval(Container.DataItem, "isVoid")%> </ItemTemplate>
0
7177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7123
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...
0
7542
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...
0
5701
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...
1
5100
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...
0
3248
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...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
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
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.