Solved

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

Posted on 2010-09-16
4
790 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

778 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