.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

databind a selected gridview row to a couple of formviews

Posted By:      Posted Date: October 19, 2010    Points: 0   Category :ASP.Net

 I have tried several ways but just cannot figure our how to populate some formviews with the data I have brought up in a gridview.

Here is my code so far. I just showing the code behind because my gridview and forms are not a problem. Where I am stuck  is at the GridView1_SelectedIndexChanged at the bottom of the code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WorkSheetPrint : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    protected void CheckBoxes(object sender, EventArgs e)
        string str = "SELECT P.CBID, P.CBAddress, P.PAddress, PP.PowerID, PP.EStage, PP.Status, FROM P LEFT JOIN PP ON P.CBID = P.CBID WHERE PP.EStage IN (";
        int flag = 0;
        foreach (ListItem li in CheckBoxList.Items)
            if (li.Selec

View Complete Post

More Related Resource Links

Gridview that exports selected rows to Excel

his seems like a messy workaround, but I ended up using two Gridviews - one to display my data and show my checkboxes, and the other which was invisible amd would eventually end up as my Excel spreadsheet.

How to let user edit selected gridview columns, not entire row



I've got a gridview I would like to let the user edit a couple of columns.  Seems like everything I'm coming across so far makes the entire row editable.  

Hopefully the solution isn't too complicated.  Can someone point me in the right direction?


Rendering data with HTML tags in the DD Gridview for a selected column


I am having trouble finding out where and how to HTML Encode a cell's data on the Dynamic Data (v4.0) gridview of List.aspx.  As a simple case, suppose I have formatted cell data that is A<br/>B in the DB.    Obviously, I want A stacked on B in the cell.

It seems gridView1.HtmlEncode = true has gone away.

So maybe I'll try to catch it on the RowDataBound event:

protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)

            if (e.Row.RowType == DataControlRowType.DataRow)
                // Html Encode the cells


but this event never fires?

Has anyone figured out how to properly render HTML tags data in the List.aspx's GridView1? 

If I figure this out, then I can add a MetaAttribute called something like [EncodeAsHtml(true)] and be on my way.  Thanks!

Gridview Selected Value is Not a Primary Key

Hello,  I have 2 GridViews.  One is working perfectly.  What I would like to have happen is when a row is selected on GridView1 (with Primary key of OrderNumber), the matching records from the field in GridView1 ClientID to show up in GridView2. <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="\\sjfileserver\data\database\S.J. Rollins Technologies Information Center.mdb" SelectCommand="SELECT [ClientID], [OrderNumber], [Field1] FROM [ORDERS] WHERE ([ClientID] = ?)"> <SelectParameters> <asp:ControlParameter ControlID="GridView1" Name="ClientID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:AccessDataSource> <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="AccessDataSource2"> <Columns> <asp:BoundField DataField="CustomerID" HeaderText="ClientID" SortExpression="ClientID" /> <asp:BoundField DataField="OrderNumber" HeaderText="OrderNumber"

Selected Value in Gridview not Accessable via SelectedIndex

I'm trying to keep these questions seperate for people searching after me, so sorry if there is so many.I have the following code on SelectedIndexChange of GridView1HFCustomerID.Value = GridView1.Rows(GridView1.SelectedIndex).Cells(6).Text.ToString()I have a drop down list that you can choose values from, and depending on which item you pick GridView1 changes, this all works correctly, and if I select one of the rows the SelectedIndex changes.  My problem occurs when you choose a different value from the drop down list, GridView1 Changes accordingly, and by default a record is selected.  But selectedindexchange is never fired again until I manually select another record from the gridview which is a problem.Any Ideas?  Am I putting this code in the incorrect place?

When to call DataBind on GridView?

So I have a GridView and several events that can be triggered (such as filtering and inserting a new record) to manipulate the GridView.  I want to make sure that I'm not calling DataBind on Page_Load, especially since I might have to call it again when certain events fire.  Is there a way I can make it so I only have to call DataBind once on the GridView after Page_Load and anything else has fired?  Like some event that will absolutely fire last where I can put my DataBind?  The reason I need to do this is because the DataSource for the GridView is set programmatically from a DataView when the page is loaded, so DataBind needs to run every time.  Just, hopefully, not multiple times each time...

Databind on Gridview throwing System.InvalidCastException. Specific Cast Not Valid

Hello, I am working on a web app where when the user enters data into a text box and presses a filter radio button it should filter the Gridview on the page to the criteria entered.  I have done this before in previous applications with the same code listed below, but for some reason I am now getting the InvalidCastExeption error.  Any help would be appreciated, the source database is SQL and the data field is set to nvarchar and I am using a string to compare as you will see in the code.  I am just unsure why this worked in the past and is not working in this scenario. Thanks, Pete protected void filterLName_CheckedChanged(object sender, EventArgs e) { SHCDataContext existingCustomers = new SHCDataContext(); var filterExistingCustomers = existingCustomers.Customers.Where(c => c.custLastName.Contains(lNameTB.Text.ToString())); displayCustGV.DataSource = null; displayCustGV.DataSourceID = null; displayCustGV.DataSource = filterExistingCustomers; displayCustGV.DataBind(); }   Here is the stack trace....  Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.I

Gridview Dropdownlist Databind

Hi All, I am trying to Bind data dropdown list column only inside the gridview  while pageload using asp.net with c#.  I am able to bind the data to it but it is creating rows for total list itmes.  I want to bind to that at the first time i can able to see only one row. Later When i click on any one of the column then it will create a new row. Regards,

Get selected row value based on checkbox selected in gridview using jquery

Hi ,    i am having gridview with two columns.one column contains checkboxes and another column contains Name.i have given UserId to DataKeyNames in gridview.Now i will check some checkboxes in gridview and click on button GetData. whenver i click on button GetData i need to get datakey values of all the gridview rows whatever checked in gridview using JQUERYPlease help me i am new to JQUery

How to get row value when a row is selected or clicked in gridview

Hello, I have a gird view,which has only one field displayed,and a text box. (Grid view has 2 data rows.) On the gridview i have a button field named "Detailed View" which has command name "Detailed". When i click on the row 1 i wanted to display the value on the text box How will I execute it? I have given the following code but its not giving me the expected result.textbox1.Text = datagrid.Rows(e.CommandArgument).Cells(0).Text) and on the gridviews _RowCommand event Its showing null I am using VS 2008 (.net version 3.5) AND MS ACESS DB In visual studio 2005(.net 2.0) the same code is working absolutely fine ThanksNick

Print a specific Access Report with selected GridView record

I have my code output a gridview with all the data with an option to select records. I'm trying to make a code which would allow me to select a record, and then print this record using a specific Report stored in MS Access. I've located the code to print the Report it self, but it prints ether all the records or a range. Any ideas? 

Display selected items total in gridview footer


Hi all,

           I will have a gridview with checkboxes and some amount fields. I would like to display the sum of the amount in gridview footer depending on the checked items by the user. Can any one give me a sample code

radio button in gridview not storing the selected value


hi i have a grid view with radio button...schedule/approve/reject...by defualt schedule radio button is selected....but when i chage radio button selection option to anyth other than schedule it still store only schedule in DB.wats the pblm?could someone help me>

<asp:GridView ID="Gridgpapp"  runat="server" DataSourceID="ApprovalGp" AutoGenerateColumns="False" 
            AllowPaging="True" AllowSorting="True" BorderColor="#3366CC" BackColor="White" BorderStyle="None" 
            BorderWidth="2px" CellPadding="4" ShowFooter="True" EmptyDataText = "No Gatepass waiting for Approvals">
              <RowStyle BackColor="White" ForeColor="#003399" />
                   <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                   <PagerStyle BackColor="#99CCCC"  HorizontalAlign="Left" />
                   <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                   <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />

How Get selected cell values from gridview


How Get particular selected cell value from gridview . my grid so many cell available..

i'm created dynamic row and cell ...

Can't edit GridView columns after it's DataBind()


I have a gridview in my web application.  I use a SqlDataAdapter to fill a datatable, and then set my GridView's datasource as the datatable and do a DataBind() on the GridView.  But before I do the datasource selection and the databinding, I try to copy the first column and place it in the second column, and have an autoincrement in the first column ("1", "2", "3", etc.), but it the GridView is just blanked out then.  If I DON'T mess around with those columns then the GridView looks just normal like it should.

What could be going wrong with this???  My method is not working.  Any help is much appreciated.  Thanks in advance. :)

How can i hide selected rows from gridview


Can u tell me how can i hide selected rows from girdview using javascript.

two gridviews same page - unselect selected row when row selected in second gridview



New to asp.net and struggling with a problem.

I have two gridviews on same page - If a record is selected in Gridview1, I need to unselect a record (if one is selected) in Gridview2 - and vice-versa.

Can this be done?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend