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

Top 5 Contributors of the Month
Sandeep Singh
Post New Web Links

Row command working on all rows not selected one?

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net


I have this code that hides a column in a gridview.  (The column houses another nested gridview).

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "Select" Then
            If GridView1.Columns(0).Visible = False Then
                GridView1.Columns(0).Visible = True
                GridView1.Columns(0).Visible = False
            End If
        End If
    End Sub

The trouble is that if I click the select link on one row that action to hide is carried out on all rows.  How can I set this up so that it only hides the row that is selected?


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.

ListView.ItemTemplate with Button. Command doesn't execute when item is selected

I have a listview with an item template that contains a button: <ListView ItemsSource="{Binding AllProducts}"> <ListView.ItemTemplate> <DataTemplate> <Grid> <Button Content="Add Supplier" Command="{Binding AddSupplier}"/> </Grid> </DataTemplate> </ListView.ItemTemplate> </ListView> When the listitem is not selected and the button is clicked, the command executes fine. However, if the listitem is selected, the command does not execute. I have tried putting click and mouse down event handlers on the button, but the events do not fire. Is there any way to make the command execute when the listitem is selected?

How can i hide selected rows from gridview


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

delete selected rows from ListView


Hi All.

My ListView has chechbox column and I would like to select some rows in ListView and delete them by click Delete button. That is code of Delete procedure.

  Private Sub DeleteSvcButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles DeleteSvcButton.Click  
  If Not IsNothing(Me.ListView1.SelectedValue) Then
   If ListView1.SelectedItems.Count > 0 Then
    For i As Integer = 1 To ListView1.SelectedItems.Count
     Dim TestDataRow As System.Data.DataRowView
     TestDataRow = ListView1.SelectedItems(i - 1)
     Service_Id = Me.ListView1.SelectedValue

Insert command not using selected value from DDL in a DetailsView


My web form contains a detailsview control that I have added a templated field to with a DropDownList in the InsertItemTemplate. The DetailsView default mode is 'insert. My detailsview is attached to a sqldatasource that has a stored procedure in the db to handle the insert. When I enter data in the fields and select insert all values from the detailsview are written to the table except for the selection that was made in the dropdownlist. I am using the ddl.selecteditem.value to populate my variable however when the insert method is envoked it doesn't send my value. The DDL value that I am capturing does not need to be written to the table it is just a flag for some variables that need to be set at the stored proc level. How do I get the DDL selected value to be sent with the insert statement? Any help would be greatly appreciated.

Here is my code behind:





Protected Sub

DropDownList1_SelectedIndexChanged(ByVal sender

delete multiple selected rows


Hi All

I have a ListView that is bound to a dataset. The user has ability to select multiple rows. I would like when a button is clicked, delete all selected items. For that I use a loop but get error message: Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead. The code looks

If ListView1.SelectedItems.Count > 0 Then
  For i As Integer = ListView1.SelectedItems.Count - 1 To 0 Step -1
End If

The error message point to line ListView1.Items.Remove(ListView1.SelectedItems(i))

How to fix that problem. I will appreciate for sample.


Delete selected rows from Table



I need to delete all rows from Table A that :

1. equal in year column(tbl A) with Date column from Table B

2. A.policaNum = C.PolicaNum (from TABLE C)


THOSE tables deals with large data amount, so I'd like the best solution to this.  

I tried only to select before delete, but it takes too long and throws exception of memory

FROM    A left JOIN
           C ON A.kod_lakoha = C.kod_lakoha INNER JOIN
           B ON A.YearItra = year(B.TarichNechonot)



Connection timeout and command timeout : they working?


Hello everyone
I'm checking these parameters to connect to a server from a wireless client in the presence of little or no coverage to alert the operator of the problem.
I tried to lower both the timeout to 5 seconds. But if there is no connection sometimes takes 90 sec. sometimes only 45sec. first to tell me that is not 'unable to contact the server.
The connection string I use is' this:
Provider = SQLOLEDB.1; Persist Security Info = False; User ID = sa; Initial Catalog = Ideabiella; Data Source = localhost; Connect Timeout = 5;
and when I open the command also sets the CommandTimeout to 5sec.
where am I wrong?

hello and thanks

Create a group from selected rows of grid




Let me see if I can explain what I am trying to do...


From a gridview a user would be able to select as many rows as they wanted and create a "custom group" ... that user group would then be available from a dropdown list for future selection. So next time they would just select the "custom group" from a dropdown list and the resulting datagrid would only have those rows that were originally selected.

So if I had a datagrid which had: empoyeeID, name, address, phone#, etc...

1. I select what ever rows I want
2. Create a name for the new custom group
3. Click a "save group" button ... this would save all the employeeID's from selected rows.
4. A dropdown list would then be updated with the new custom group ... ie, MIKE's GROUP
5. User could then select MIKE's GROUP from a dropdown list and work only with rows that were added to it.


Hope that makes sense.

Thanks in advance.


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

Dynamic Sub Menu Item Command Not working in WPF...MVVM

<MenuItem Header="Flag(s)" ItemsSource="{Binding Path=LineItemFlags}" >
                                <Style TargetType="{x:Type MenuItem}">

Sharepoint SPDatasource select command where clause not working for some columns



       I'm using MOSS 2007. I'm using spdatasource to bind a custom list to gridview using webuser control(webpart). spdatasource select command working for all columns except the status column. my status column is a choice- radio with the following options. Pending Review, Checked and Approved. I have checked the field internal name, every thing is correct, but only for status column filtering not happening. Gridview coming as blank

i tried using 

             <FieldRef Name='Status'/>
             <Value Type='Choice'>Pending Review</Value>

Any idea?????




SP Datasource select Command not working for Status Column



    (MOSS 2007-Webuser control Web part)

    I'm having a cutom list that i'm binding using SPDatasource to a gridview. I want to filter the list based on column values. I tried the following code

            SPList taskList = site.Lists["Accounts"];
            SPDataSource mySPDS = new SPDataSource();

         mySPDS.SelectCommand = "<View><Query><Where><Eq><FieldRef Name='Vendor_x0020_Name'/><Value Type='Text'>"+ddlVendorName.SelectedItem.Text +"</Value></Eq></Where></Query></View>";


mySPDS.SelectCommand = "<View><Query><Where><Eq><FieldRef Name='Status'/><Value Type='Choice'>" + ddlStatus.SelectedItem.Text + "</Value></Eq></Where></Query></Vi

Command Binding not working when the host control is added programatically in wpf


This is weird. I have a UserControl (MyControl) with a button inside. I have added a command to this button whose command target is another user control which is again added to the same window.

When I add the UserControl statically in xaml to the CustomControl's host space, the CommandBinding system works fine, where as the same doesn't work if the UserControl is added programatically (on Loaded event of this Window).

What could be the reason. Am I missing something in here ?!?


A better representation of my words as an image. Also I have uploaded my source code with binaries @ https://code.google.com/p/commandbindingsample/

Image @ http://codelog.blogial.com/files/scenario.png


Copying rows using a dynamic SQL Command variable


I have a table with the Source TableName and Source ColumnName. I am trying to use SSIS to extract data from my source based on the tables and columns. I am using a Script Task to dynamically create the SELECT statement, no problems with that.

Next, I have a data flow task with a Source OLE DB Connection and the Data Access mode is using this dynamically created select statement. I am however unable to use this because this SELECT statement variable is not populated until runtime.

Basically I want to COPY ALL ROWS from the source to a destination. 

Is this possible? What is wrong with my assumptions? Any suggestions?


You are so wise...like a miniature budha covered in fur. -Anchorman

ado command does not insert all rows


In my C++ code, when I try to run the ADO command to insert rows into a table, it only inserts a certain number of rows. The same command works when using System.Data.SqlClient in .NET. 

Sql profiler shows the same textdata. Below is my insert commandtext, I'm not sure what else to do to uncover the issue here. Any help on this is appreciated.

Command text : 

declare @i int set @i = 1 while (@i < 255) begin insert into table1 (name,type, order, state) values (@i, N'type',0,0) set @i = @i +1 end

The above command ends at 153 rows. Is this dependent on table size ?

This is my connection string and the code I'm using to build the connection :

ADODB::_ConnectionPtr m_Conn = NULL;  
TCHAR connString[255];
  _stprintf(connString, _T("DRIVER=SQL Server;SERVER=np:(local)\\MyInstance;DATABASE=test;"));

   HRESULT hr;
   hr = m_Conn.CreateInstance(__uuidof(ADODB::Connection));
   if (hr != S_OK) {
     wprintf(_T("CreateInstance(__uuidof(ADODB::Connection)) failed. Error: %d"), hr);
     return 0;

   m_Conn->ConnectionTimeout = 1800;
   m_Conn->CommandTimeout = 1800;

   hr = m_Conn->Open((LPCTSTR)connString, _T(""), _T(""), ADODB::adConnectUnspecified);
   if (hr != S_OK) {

MDX for counting rows when various dimensions are selected


I am trying to do an average and found that averageofchildren doesn't roll up approrpriately, thus going to the reliable sum/count approach.

I have the measure Cur Commit = SUM([Measure].[Cur Commit] but I am having trouble doing the count. This is what my data woule look like

DevOrg Hierarchy                              Curr Commit


     ERP 4.2                                     1

     ERP 5.1                                      0

     EDW 6.0                              &nbs

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