Hi All.

I am using a GridView to List contacts linked to a logged in User.

I can successfully bind the Gridview with a DataTable. And the values in the GridView are correctly displayed.

I have a BoundField at Index 0 of the GridView which pulls a value from a Column in the DataSource (datatable).

The problem I am facing is that all the values in the cells are coming back as empty strings.

Can Anyone help me understand what I am leaving out and what I am doing wrong.

Code is as below:

protected void grdContactList_RowCommand(Object sender, GridViewCommandEventArgs e)
    {
        Global.BindGridView(ref grdContactList, Global.g_dtContacts);

        if (e.CommandName == "EditContact")
        {
            string strCmdArg = Convert.ToString(e.CommandArgument);           
            string strContactID = grdContactList.Rows[Convert.ToInt32(strCmdArg)].Cells[0].Text;           
            Server.Transfer("EditContact.aspx?contactid=" + strContactID);
        }
        else if (e.CommandName == "DeleteContact")
        {
            string strCmdArg = Convert.ToString(e.CommandArgument);
            string strContactID = grdContactList.Rows[Convert.ToInt32(strCmdArg)].Cells[0].Text;
            string strAgentID = grdContactList.Rows[Convert.ToInt32(strCmdArg)].Cells[1].Text;
            Contact.DeleteContact(strContactID, strAgentID);
        }
    }

The values of both strContactID and strAgentID are coming back as "".

BindGridView(...) is basically...

GridView.Datasource = dtDatatable;
GridView.Databind();

Thanks.

Recommended Answers

All 2 Replies

Are you sure that the Cells directly contain the values in them, and they're not contained in a label within the Cell?

To get a data grid view cell value in a given variable do as follow
I give u two samples

assuming that my variable is a string
string myVariable;
int myRowIndex=0;
int myColumnIndex=0;
myVariable = oDataGridView[myRowIndex,myColumnIndex].ToString();

assuming that my variable is an integer
string myVariable;
int myRowIndex=0;
int myColumnIndex=0;
myVariable = Convert.ToInt32(oDataGridView[myRowIndex,myColumnIndex]);

That's it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.