c# gridview select on button click -


i've got gridview templatefield set button, have code on onclick event works fine if row selected.

what i'm struggling find way select row using button_click.

<asp:gridview id="gridview2" runat="server" autogeneratecolumns="false"                 datakeynames="ordersummaryid" datasourceid="sqldatasource1"                 onselectedindexchanged="gridview2_selectedindexchanged" width="1230px">      <columns>          <asp:boundfield datafield="ordersummaryid" headertext="ordersummaryid"                           readonly="true" sortexpression="ordersummaryid" />          <asp:boundfield datafield="bariatricrequestid" headertext="bariatricrequestid" sortexpression="bariatricrequestid" />          <asp:boundfield datafield="devicetypeid" headertext="devicetypeid"                           sortexpression="devicetypeid" />          <asp:boundfield datafield="devicetype" headertext="device type"                           sortexpression="devicetype" />          <asp:boundfield datafield="subcategory" headertext="sub category"                           sortexpression="subcategory" />          <asp:boundfield datafield="make" headertext="make"                           sortexpression="make" />          <asp:boundfield datafield="model" headertext="model"                           sortexpression="model" />          <asp:boundfield datafield="weightlimit" headertext="weight limit"                           sortexpression="weightlimit" />          <asp:boundfield datafield="devicesearchresultstatus" headertext="device source"                           sortexpression="devicesearchresultstatus" />          <asp:boundfield datafield="reqconfirmdatetime" headertext="confirm date/time"                           sortexpression="reqconfirmdatetime" />          <asp:boundfield datafield="localdeviceassetid" headertext="internal asset id"                           sortexpression="localdeviceassetid" />          <asp:templatefield headertext="confirm order">              <itemtemplate>                  <asp:button id="button1" runat="server" onclick="button1_click"                               text="button" />              </itemtemplate>          </asp:templatefield>      </columns>  </asp:gridview>

protected void button1_click(object sender, eventargs e)  {      var rowid = gridview2.selectedrow.cells[0].text;      string source = gridview2.selectedrow.cells[8].text;      var assetid = gridview2.selectedrow.cells[10].text;

try use piece of code grabbing row button clicked. might not exact thing should progress further.

 protected void buttonsubmit_click(object sender, eventargs e)     {      gridviewrow grow = ((gridviewrow)((button)sender).parent.parent);     } 

based on how nested button is, need use parent reference per that.

hope helps.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -