0
votes

I am having a GV (which I am populating through code behind) in which I want to UPDATE the items the row that I selected in.

Here is what I am populating in my GView:

  var td = from s in GetEntity()
                 join r in GetPlanName() on s.Product_ID equals r.Product_ID
                 where s.Entity_ID == getEntity
                 select new
                 {
                     s.Product_ID,
                     r.PlanName,
                     s.HiCommissionOld,
                     s.LowCommissionOld


                 };
        gvShowComm.DataSource = td;
        gvShowComm.DataBind();

Here is the mark up of my GV:

<asp:GridView runat="server" Height="233px" Width="602px" ID ="gvShowComm" 
    CellPadding="4" ForeColor="#333333" GridLines="None" 
    EnableViewState="False" OnRowEditing = "gvShowComm_RowEditing" 
    OnRowUpdating = "gvShowComm_RowUpdating" 
    OnRowCancelingEdit = "gvShowComm_RowCancelingEdit" 
    DataKeyNames = "Product_ID" >



    <Columns>
        <asp:CommandField ShowCancelButton="True" ShowEditButton="True" />
    </Columns>
 </asp:GridView>

And here is my Code Behind:

 protected void gvShowComm_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
          int index = gvShowComm.EditIndex;
        GridViewRow row = gvShowComm.Rows[index];
        string name = row.Cells[2].Text; //name is empty!
    }

So here is my problem: I can access one column through DataKeyNames property in my GView tag, but I have to access other elements in order to UPDATE my Grid View through LINQ in the code behind. The reason why I am NOT using LDS because I am updating tables from 2 different databases.

Thank you!

1
so you're just trying to figure out how to access other column information in the rowupdating handler? - BrandonZeider
Please stop posting comments as answers. This is not a forum, it is a question and answer site. If you need to post more information about your question, edit your question to add the additional information. - Robert Harvey

1 Answers

0
votes

You can access the other cells in the row like this. Take a look at this link for more details.

gvShowComm.Rows[e.RowIndex].Cells[index]