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

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

Selected Value in Gridview not Accessable via SelectedIndex

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :ASP.Net
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?

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"

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 ...

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?


Change selected row background color in gridview using javascript


hi frineds,

              i have a gridview with radio buttons in gridview i have chance to select only one item at a time in gridview like this

i need to change the row color of selected item in gridview with radio button using javascript if i select second row with radio button first row comes to normal condition now second row is in selected mode please help to write this functionality using javascript

code behind - variables and gridview-selected data



I'm a newbie using VWD 2010 Express, asp.net 4.0.  

I'm also learning VB and C#.  I'm pretty lost, so please direct me. 

I'm trying to understand the code-behind behind gridview select/edit buttons.  I'm not sure whether I need to look for asp.net or VB/C# tutorials. 

   protected void ds_Selecting(object sender,SqlDataSourceSelectingEventArgs e)

Using above example, 
1. How do I access the user-selected row data from the gridview in the code-behind? 
2. What is 'sender' and 'e'? 

If there's a tutorial that explains these, please direct me.

Thank you!

Comparing Selected value against GridView Column



             I have a GridView Column "Gender". After displaying datagrid, I m selecting dropdown which is not in datagrid.

Dropdown list is in the same page. When I select dropdown Gender as male or female, I have to validate that Gender against GridView Column. If that Gender Exist in GridView, I have to display message.


Gridview row sometimes has to be selected twice for code to work


I'm using the code below to extract data from a gridview and populate it into textboxes for the days and two drop downs for Project and Category.

For some rows in the gridview everything but the category ddl populates correctly. If I click the row a second time the category ddl displays the correct category.

Can anyone tell me why I have to click twice for some rows? And how do I fix this?

Thank you

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    //// Get the currently selected row using the SelectedRow property.
    GridViewRow row = GridView1.SelectedRow;

    txtSunday.Text = (row.Cells[6].Controls[0] as DataBoundLiteralControl).Text.Trim();
    txtMonday.Text = (row.Cells[7].Controls[0] as DataBoundLiteralControl).Text.Trim();
    txtTuesday.Text = (row.Cells[8].Controls[0] as DataBoundLiteralControl).Text.Trim();
    txtWednesday.Text = (row.Cells[9].Controls[0] as DataBoundLiteralControl).Text.Trim();
    txtThursday.Text = (row.Cells[10].Controls[0] as DataBoundLiteralControl).Text.Trim();
    txtFriday.Text = (row.Cells[11].Controls[0] as DataBoundLiteralControl).Text.Trim();
    txtSaturday.Text = (row.Cells[12].Controls[0] as DataBoundLiteralControl).Text.Trim();

    // Set ProjectList ddl to Project in selected row
    if (ProjectList.Items.FindByText

GridView Selected rows validation


Hi All,


I want some solution for my gridview to validated only selected rows.


What is the senario:


In my gridview there are 1 templatecolumn - Total Balance -txtTotalBalance


1 another templatecolumn - Amount Received -txtAmountReceived


There are checkboxes

I want to compare only that row which is checked with txtTotalBalance with txtAmountReceived  should not be greater than totalbalance.


In current code all rows validating compare validator.That I don't want.


Please give me solution-If possible then please send me the code also..

Thanks in advance

Swapnil Malviya

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