2015-03-06 9 views
0

Я пытаюсь выбрать значение из gridview, но я возвращаю пустую строку.Почему значение ячейки сетки возвращает пустую строку?

<asp:GridView ID="GridViewLedger" runat="server" Width="100%" AutoGenerateColumns="False" 
         ShowFooter="True" DataKeyNames="AccountID" OnRowCommand="GridViewLedger_RowCommand" 
         CssClass="table table-hover table-striped table-bordered"> 
         <Columns> 


          <asp:TemplateField HeaderText="InvoiceNo" SortExpression="InvoiceNo"> 
           <ItemTemplate> 
           <asp:LinkButton ID="btnClickInvoiceNo" runat="server" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" CommandName="InvoiceNo" Text='<%# Eval("InvoiceNo") %>' /> 
           </ItemTemplate> 
          </asp:TemplateField> 

         </Columns> 
        </asp:GridView> 

Я удалил все ненужные столбцы здесь,

protected void GridViewLedger_RowCommand(object sender, GridViewCommandEventArgs e) 
    { 
     int index = Convert.ToInt32(e.CommandArgument); 
     string InvoiceNo = GridViewLedger.Rows[index].Cells[4].Text; 
    } 
+0

Вы пробовали отладки, чтобы увидеть, какие значения строка имеет? – RePierre

+0

Да, он возвращает 1, как и ожидалось –

ответ

3

Вы не можете получить доступ к тексту LinkButton внутри ItemTemplate в виде TemplateField путем доступа .text из rowcell.

Что вы можете сделать, это

LinkButton lbInvoiceNo = GridViewLedger.Rows[index].Cells[4].FindControl("btnClickInvoiceNo"); 
string invoiceNo = lbInvoiceNo.Text; 
0

попробовать ..

if (e.CommandName == "InvoiceNo") 
    { 
     int index = Convert.ToInt32(e.CommandArgument); 
     string InvoiceNo = GridViewLedger.Rows[index].Cells[4].Text; 
    } 

Try2:

 if (e.CommandName == "InvoiceNo") 
     { 
     int index = Convert.ToInt32(e.CommandArgument); 
     GridViewRow row = GridViewLedger.Rows[index]; 
     string InvoiceNo=row.Cells[4].Text; 
     } 
+0

такое же:/no effect –

Смежные вопросы