473,854 Members | 1,637 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 1246
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="Whit e" CellPadding="4" AllowSorting="T rue"
AutoGenerateCol umns="False" GridLines="None "
CellSpacing="2" AllowPaging="Tr ue" PageSize="20" EnableViewState ="False"
OnItemCommand=" GetRowInfo">
<AlternatingIte mStyle Wrap="False"></AlternatingItem Style>
<ItemStyle Wrap="False"></ItemStyle>
<PagerStyle NextPageText="N ext" PrevPageText="P revious" Wrap="False"
Mode="NumericPa ges"></PagerStyle>
<Columns>
<asp:BoundColum n DataField="myNa me" SortExpression= "myName"
HeaderText="My Name"></asp:BoundColumn >
<asp:BoundColum n DataField="some text" SortExpression= "sometext"
HeaderText="Act ive"></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Cho ose Row">
<ItemTemplate >
<asp:imagebutto n CommandName="bt nEdit" id="btnEdit"
runat="server" ImageUrl="~/img/edit.gif" ToolTip="Edit"> </asp:imagebutton >
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:datagrid>

Protected Sub GetRowInfo(ByVa l source As Object, ByVal e As
DataGridCommand EventArgs)
'Grid paging/sorting causes this event to fire and e.Item.ItemInde x=-1
so we should avoid an error by coding for this case.
If e.Item.ItemInde x >= 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).PageS ize *
CType(source, DataGrid).Curre ntPageIndex + e.Item.ItemInde x

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.Redire ct("~/MyEditPage.aspx ")
End If

End If

End Sub

--
Joe Fallon

"Anna" <BC*****@gmail. com> wrote in message
news:11******** **************@ l41g2000cwc.goo glegroups.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
5397
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 site to create a basic .asp query form (too long to post it here), but it always displays: No...
0
1758
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 wrong path here. Essentially, here is an explanation of my ASP.NET webform application and what I want...
4
4109
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 union, but not the keyword distinct. The query is displayed in a datagrid, and I don't know how I...
2
2924
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 this within the databinding event of the grid, but am unsure as to quite how!
2
1179
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 please point out my error, I am new at this, and would appreciate some help. thanks, student Here's...
3
1885
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
1941
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
2265
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 in hopes on not having to trouble others on those. But here it goes...
0
1179
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
9750
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10744
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,...
1
7909
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
7077
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5738
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...
0
5937
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4550
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
2
4150
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3182
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.