Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

726 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