Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

GridView Control

Posted on 2006-11-09
5
Medium Priority
?
290 Views
Last Modified: 2012-05-05
hi all... i am using this section of code to capture a row cell that is clicked by the user...

 public void DataGridID_ItemDataBound(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {
        int l;
        int index = Convert.ToInt32(e.CommandArgument);
        // Retrieve the row that contains the button clicked by the user from the Rows collection.
        GridViewRow row = GridView1.Rows[index];
        l = int.Parse(row.Cells[2].Text);       //Get id

....
    }

the problem is that when i add sorting and paging to the the grid via the "smart tag" the following line "int index = Convert.ToInt32(e.CommandArgument);" catches the column value which is a string and errors out.  What is the correct way to go about paging and sorting my grid using the following code i have posted.  
0
Comment
Question by:joan2006
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:kraffay
ID: 17910889
I suggest isntead using:

  int index = e.Item.ItemIndex;


0
 
LVL 1

Expert Comment

by:riyaz404
ID: 17911895
You might have already done this, but if not...

Do you use the DataSourceID instead of DataSource to bind?
If you use DataSourceID to bind, then you will not have to worry about paging or sorting events. They dont need to be handled..You cannot assign a regular DataSet or DataView to DataSourceID

You need to assign, SQLDataSource or ObjectDataSource..SQLDataSource can be used to bind a query written in Oracle, SQL Server, or any other Database. Its not like your SqlDataAdaptore or OracleDataAdapter in framework 1.1
0
 

Author Comment

by:joan2006
ID: 17979875
kraffay ,

There is not an option for e.Item.ItemIndex;
 only CommandArgument, CommandName, CommandSource, Equals, GetHashCode, GetType and ToString ...


Any more suggestions
0
 

Author Comment

by:joan2006
ID: 17981857
riyaz404,

Help me with the paging ...you say if i use DatasourceID then i dont have to code for paging..

i get an error:

Error      1      Cannot implicitly convert type 'System.Data.DataSet' to 'string'      

this is how i am using it... please help me figure this out..
               
             DataSet ds = GetAllWFXLSFiles();

                if (ds.Tables[0].Rows.Count > 0)
                {
                   // GridView1.DataSource = ds;
                    GridView1.DataSourceID = ds;  //try datasourceid instead
                    GridView1.DataBind();  org
                    //GridView1.DataSource = ds.Tables[0].DefaultView;
                    ds.Dispose();
                }

0
 
LVL 1

Accepted Solution

by:
riyaz404 earned 2000 total points
ID: 17982039
to use dataSourceID, you need to you use the new datasourcecontrols of .net 2.0.

Build a datasource control, by dragging one from toolbox. Once you have that, you can use the name of that datasourcecontrol to assign to the datasourceid.

You cannot assign a dataset as a datasoureid. It has to be a classname that is of type DataSourceControls.

Like this -
(following goes in the aspx file)

<asp:SqlDataSource ID="CustomersList" Runat="server"
SelectCommand="SELECT CompanyName, ContactName, ContactTitle, City FROM Customers"
ConnectionString=
"Data Source=127.0.0.1;Integrated Security=SSPI;Initial Catalog=Northwind">
</asp:SqlDataSource>

<asp:GridView id="MyDataGrid" DataSourceID="CustomersList" runat="server"/>

Or in your code (cs file) -
MyDataGrid.DataSourceID = "CustomersList";


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question