Datagrid Row Row/cell selection

I have a data grid that is displaying the results of a query to a database.  It has 4 columns (say appID, FAQID, FAQ, Source).

I have created the FAQ column as a TemplateColumn and set it as a LinkButton as I want a new page of the application to load when a user clicks on the FAQ.
The new page is to display to complete solution to the FAQ. Is there any way that I can retrieve the value from the FAQID column that relates to the clicked FAQ so that I can pass this to the new usercontrol?
Regards,
Wallace
0
wallaceoc
8/25/2004 6:07:33 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
680 Views

Similar Articles

[PageSpeed] 34

You could certainly do this. Since you have the FAQID in the one of the cells of the DG, you could assign an event handler to the OnItemCommand event handler in the design view of the DG and then define the code needed to accomplish what you are trying to in the code behind.

To access the DG cells and its values, u cud write code somehting like below

protected void GetFAQID(object sender, DataGridItemEventArgs e)
{
e.Items.Cells[index value of the cell in which you have the FAQID];
....
....
}

By accessing the cell values u could get to the values in it and then do what u are trying to accomplish.
hth

Shravan Addaypally MCP

0
shravan79
8/25/2004 7:09:03 PM
Thanks for the help hth.

I've just got a few questions:
How do you access the OnItemCommand event handler?
If I double-click on the DataGrid in design mode the event is:

private void faqResults_SelectedIndexChanged(object sender, System.EventArgs e)
{
}


An there is nothing in the properites that states OnItemCommand.
I tried coding myself and this is what I've come up with but I'm not sure if its right. Here is a few snippets of the code:

protected System.Web.UI.WebControls.DataGrid faqResults;
....
....
....
private void InitializeComponent()
{
this.faqResults.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.getFAQID);
this.faqResults.SelectedIndexChanged += new System.EventHandler(this.faqResults_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}

protected void getFAQID(object sender, DataGridCommandEventArgs e)
{
Response.Write("Test: " + e.Item.Cells[1]);
}

Can you see any problems with this?
Thanks,
Wallace
0
wallaceoc
8/26/2004 9:22:17 AM
It may also help if I give you my code from html view:


<asp:DataGrid id="faqResults" style="MARGIN-BOTTOM: 5px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 3px"
runat="server" Width="678px" BorderStyle="None" BorderWidth="1px" BorderColor="#999999" HorizontalAlign="Center"
BackColor="White" CellPadding="3" GridLines="Vertical" AutoGenerateColumns="False"
OnItemCommand="getFAQID">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#000084"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="APP" HeaderText="APP">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Middle"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="FAQ ID" HeaderText="FAQ ID">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Middle"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="FAQs Found" ItemStyle-HorizontalAlign="Justify" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle">
<ItemTemplate>
<asp:LinkButton id="solutionLnk" runat="server" Font-Bold="False" CommandName="LoadCommand" Text='<%# DataBinder.Eval(Container, "DataItem.FAQs Found") %>' CausesValidation="False" Font-Underline="true">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Criticality" HeaderText="Criticality">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Middle"></ItemStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
0
wallaceoc
8/26/2004 9:25:21 AM
I know this is going on a bit but I'm having another problem.  The way I'm designing my application is that I'm using user-controls.

I have a main page - "WebForm.aspx", which is split into 2. The left side holds a serachPage.ascx that constantly remains in the WebForm. However the right hand side changes according to the users interaction.
Therefore, the reason I'm having a problem is becuause when the user clicks on the link in the datagrid I want a new usercontrol to load. I need some sort of event to fire so that I can send the FAQID (talked about in my first post) to a new usercontrol (solution.ascx) that is to load.
Any ideas?
0
wallaceoc
8/26/2004 11:08:27 AM
Nothing seems to be wrong with this. Did u try if it worked??
Shravan Addaypally MCP

0
shravan79
8/26/2004 2:53:10 PM
Yes I tried it but it doesn't work.  I am using user controls and I think I'm having problems passing the data between user controls.  Somebody mentioned it may be because I have to recreate dynmaically added user controls after postbacks?

Does that sound familiar to you?
Wallace
0
wallaceoc
8/26/2004 4:05:16 PM
Reply:

Similar Artilces:

How to set the row number and get the row number for ("selected row) in Datagrid
I face a problem that i can't get the selected row of the datagrid in both server side script (VB.net) and client side script (javascript) As i can't use the button column / hyperlink column in the datagrid. Thus , i need to handle the change the background color of the selected row and also to get the selected row number for Update/Delete. Thanks in advance. This depends on how do you perform the selection. Do you want to implement chaning of the SelectedRow at the client side without any postback? If you have no issues with postback, then you can do s little trick here: 1. ...

I want to select top 3 rows except the first from 4 rows of a Table. It should select from top 2 row,top3 row and top4 row.
 Hi, Let say I've 4 rows in a table. I want to select top 3 rows except the first from 4 rows of a Table. It should select from top 2 row,top3 row and top4 row. Thanks in advance Asghar Ali Mohammed http://www.aliwebdev.com(Web Designer and Developer)Do not forget to "MARK AS ANSWER" on the post that helped you. If you can use Linq, you can use Skip. http://msdn.microsoft.com/en-us/vcsharp/aa336757.aspxThanks, EdMicrosoft MVP - ASP/ASP.NET Hii dear..U can fire the Query select Top(3) from Table1 order by id desc.. "A conclusion is whe...

select the row of the datagrid whose value is same as one of the value of row of datagrid
hellow all,  I have a datagrid which is bound to the ordertable,so all the orderdetails are shown on the page load. but my requirement is that,i have a textbox and a search button,when the user enter the order number in the text box and click on the search button the datagrid should show that record whose order number is entered by the user n most imp that the record may be in the 65th or 34th row of the datagrid,i wants to put it in the first row. how to do it. If there's a reason you can't filter down to just the one row, you'll have to come up with some paging algorithm that wil...

How to delete Datagrid row if that row is not selected
Hi, I faced a problem. I have a simple datagrid. It allows user to select a particular row of data say row 5. It works completely fine but if user wants to delete row 7 when row 5 is selected, the datagrid will delete 5 (which is the selected row) instead of 7. How to go about this issue? Thanks! Regards, FrancisSGDOTNET.ORG Can't you just select row 7 and delete it?Thanks!Bernie At first, DataGrid deletes nothing. It sends out only commands that your code has to handle. You have to use DeleteCommand event of datagrid. In this event you have to take the row index from event...

Select a Row in DataGrid and Delete this Row
My goal is to put the Rows from one (left) GridView into the secend (right) GridVIew.For this I would like to use Drag and Drop becauce this would do just that but I can find only D&D features in e.g. Dojo. Is it possible in ASP.NET, too?Because I didn't find the D&D solution for ASP.NET I created two GridViews with a SELECT Label for choosing a Row. Then I chosen the SelectedIndexChanged event but when I want to delete the selected row then an error occurs that this isn't possible. Does anyone knows how I can solve my problem? Thank you!  Hello!!Plz see following lin...

Selecting a Datagrid row by clicking the row
Hello I am trying to configure my Datagrid so that I can click anywhere on the row and it will invoke the OnItemCommand event and run the associated subroutine. To do this I have created a datagrid with the following: <asp:DataGrid id="dgrdTSOverview_Approved" AutoGenerateColumns="False" OnItemDataBound="Mouseover_Hover" DataKeyField="Timesheet_id" OnItemCommand="dgrdTSOverview_Approved_ItemCommand" ShowHeader="true" BorderWidth="0" CellPadding="2" CssClass="datagri...

Row cell click select entire row?
I am trying to mimic the UI from MS CRM in the grids sections of the application. If anyone knows how to use/get hold of that grid then please let me know otherwise here is the question.   I am able to bind data to a datalist. (using ASP.NET 1.1). That's all good HOWEVER, since each column is a table cell, within that contains the label to show the data for that row/column, how can I select the entire row when the user clicks on it (from client click perhaps)? So on any column of a row, when the user clicks, I want the entire row to be selected/highlighted.   how can I...

Gridview paging enabled. Has checkbox to select the row . If user select the checkbox on one page and move to 2nd page to select the rows there also to export the selected rows to excel. But doing so
HiI am using Gridview and that has paging enabled. Using checkbox to select the particular row of the gridview to export the selected rows to the excel . Everything is working fine except for one case.Let user selected the "check" box for, five rows which user would like to export to excel (two of rows on page 1 of results and 3 of them on page 2 of results), however it only exports the 3 row details from page 2, because it seems to de-select the 2 rows from page 1 when I move to page 2 and vice versa. The code i am using is as :protected void BtnExcel_Click(object sender, EventArg...

how to select a row in datagrid and return primary key of that row?
any body? i am suck! =( pls help!! b General rule is to assign a primary column to DataKeysField attribute of the grid and then use GridItem.DataKeys(Index) to extract the valueBug [MCSD] so would that be under the SUB of GridItem_EditCommand? or Griditem_SelectedIndexChanged?? i just don't get it.. so stuck! =( b Does not matter. You can use that logic in any grid events as: dim intID=CInt(DataGrid1.DataKeys(e.Item.ItemIndex)) Bug [MCSD]...

Datagrid Sort,Select Row, Delete Row etc
Is there a way or technology where we can select a data grid row and delete it or update it without the use of javascript or call another page based on the selected row of datagrid? I donot want to do postback to the server, and would like to avoid javascript code on the client side.     abdulbq: Is there a way or technology where we can select a data grid row and delete it or update it without the use of javascript or call another page based on the selected row of datagrid? I donot want to do postback to the server, and would like to avoid javascript code on the client si...

How to get the row index of a selected row in listview control
Can someone please tell me how to get the index of a selected row in a listview.  <ItemTemplate> <asp:LinkButton runat="server" class="linkButton" id="xxxxx" Text='<%#Eval("documenttype") %>' CommandName="OpenFile" CommandArgument='<%#Eval("DocumentKey") %>'></asp:LinkButton></ItemTemplate>what you have to do is, in itemcommand event of ListView, you have to get the value of row indexif(e.CommandName == "corrospondingcommaandname"){     &nb...

DataGrid Selected Row Moves To Top Row of Grid????
Hello all, I have a data grid with a link Button column Built in Property Builder (coding in C#). Problem: When a link button is clicked, the row that was selected moves to the top row of the data grid. I need to find a way to simply keep the row where it is and highlight it. I've tried to set the back color of the selectedItem in the Format section of the property builder but nothing happens. If I use a select button highlighting the row as mentioned above works fine but i need to use a link button. If I code the click event of a select button column to response.redirect(&q...

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

Selecting a gridview row and keeping the last selected row in a gridview highlighted after mouse moves over a new row.
What is the best way to show a gridview row highlighted once selected and keep it highlighted once the mouse moves over a different row? Thanks, Steve hi,you can use <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="#FFFFFF" /> plz let me know if i misunderstood you Thanks for your help. One problem; however, is that after the row has been selected and I check the "grid.SelectedIndex" it has a value of -1 and not the index of the row that was selected on the grid. What do you recommend? Thanks, Steve hi, sorry i din...

Web resources about - Datagrid Row Row/cell selection - asp.net.presentation-controls

Selection - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Multi-state plans and selection problems
... often similar in design. In fact, it may be hard for consumers to tell them apart. The short answer is network and the longer answer is selection. ...

Doc Rivers Comments on If Kobe Bryant Deserves NBA All-Star Game 2016 Selection - Bleacher Report
Kobe Bryant is getting the legend treatment for the All-Star Game in his final NBA season, and that's totally fine with Los Angeles Clippers ...

Running back LeSean McCoy the lone Pro Bowl selection for Bills
LeSean McCoy's first season with the Buffalo Bills will end with a trip to the Pro Bowl. Maybe. The running back was the lone member of the team ...

Hulu to offer lulu of a video selection
Site created by NBC Universal and News Corp. to debut Wednesday with shows from more than 50 TV networks, cable stations, and movie studios. ...

After Protest, VA Rescinds Selection Of Phoenix VA Overseer Who Misled Congress About Wait Times
After Protest, VA Rescinds Selection Of Phoenix VA Overseer Who Misled Congress About Wait Times

Return of Yuvraj, Nehra: Selection gamble may just be the tonic India need
There were quite a few surprises thrown by the selectors as they announced the squads for Australia tour, with Yuvraj and Nehra's selection the ...

Prices For CFP and Bowl Game Tickets Dropping On Secondary Market After Selection Sunday
The College Football Playoff and bowl schedule are officially set, and ticket prices have already begun to fall on the secondary market. Both ...

AP PHOTOS: A Selection of Pictures From the Past Week
AP PHOTOS: A selection of pictures from the past week

Today’s selection of articles from Kotaku’s reader-run community: Final Fantasy Road Trip: FFXII • T
Today’s selection of articles from Kotaku ’s reader-run community: Final Fantasy Road Trip: FFXII • The Game Devs’ Feels Blog - Week 3: Radars ...

Resources last updated: 12/26/2015 12:26:04 PM