Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

930 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

9 Experts available now in Live!

Get 1:1 Help Now