Solved

asp.net vb - How to read an asp.net table cell value in a button-click event?

Posted on 2010-09-16
4
786 Views
Last Modified: 2012-05-10
I tried both of these:

   If tblTable.Rows(0).Cells(0) IsNot Nothing Then
               Dim strstring As String = "something"
   End If


   If tblTable.Rows(0).Cells(0).Text <> "" Then
                Dim strstring As String = "something"
   End If

This is the error message I get:
Specified argument was out of the range of valid values.
Parameter name: index
0
Comment
Question by:Rick
  • 2
4 Comments
 
LVL 6

Expert Comment

by:AliSyed
ID: 33694458
tblTable is data table?

Please check to make sure that the dataset is not empty.
do this
if (ds ! = nul && ds.tbltable != null && ds.tbltable.count > 0 )
0
 
LVL 13

Author Comment

by:Rick
ID: 33694563
It is a web control (asp.net table).
 
0
 
LVL 13

Accepted Solution

by:
Rick earned 0 total points
ID: 33694593
I found my own solution... will store the values of tblTable in an array then retrieve them later when I need them. It is a small table anyway. An arraylist should do it.
If anybody has a better idea, let me know.   Thanks.
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33694614
Hi,

Please check code for reading cell values (C#).

Regards,
VSS

--------------
//Default.aspx
--------------
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:table ID="myTable" runat="server" Caption="My Table" Width="107px">
        <asp:TableRow runat="server">
            <asp:TableCell runat="server">First</asp:TableCell>
            <asp:TableCell runat="server">Second</asp:TableCell>
        </asp:TableRow>
        <asp:TableRow runat="server">
            <asp:TableCell runat="server">Third</asp:TableCell>
            <asp:TableCell runat="server">Fourth</asp:TableCell>
        </asp:TableRow>
    </asp:table>
    <asp:Button ID="btnValue" Text="Read" runat="Server" OnClick="btnValue_Click" />

    </div>
    </form>
</body>
</html>

------------------
//Default.aspx.cs
------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnValue_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < myTable.Rows.Count; i++)
        {
            for (int j = 0; j < myTable.Rows[i].Cells.Count; j++)
            {
                Response.Write(myTable.Rows[i].Cells[j].Text+"|");
            }
        }
    }
}

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 36
DataGridview Currency Formating? 22 38
ConsoleSql 1 18
Iterate a dictionnary to change values 4 30
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now