Wie Sie auf eine ausgewählte Boundfield Wert aus GridView-Steuerelements im code-behind

Ich habe ähnliche Fragen, aber keine der Antworten hat mir geholfen, zu trainieren dieses problem.
Ich habe eine GridView mit einer ReadOnly-Feld wie folgt.

GridView:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
              AutoGenerateColumns="False" DataKeyNames="projectID" 
              DataSourceID="SqlDataSource1" 
              EmptyDataText="There are no data records to display." 
              PageSize="5" OnRowUpdating="GridView1_RowUpdating">
  <Columns>
    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"/>
    <asp:BoundField DataField="prID" HeaderText="prID" SortExpression="prID"/>
    <asp:BoundField DataField="projectName" HeaderText="projectName" 
                    SortExpression="projectName" />
    <asp:BoundField DataField="projectType" HeaderText="projectType" 
                    SortExpression="projectType" />
  </Columns>
  <EditRowStyle CssClass="GridViewEditRow"/>
</asp:GridView>

wie Sie sehen können die prID BoundField hat Readonly=True Attribut.
Ich versuche, den Wert der prID im code-behind-wenn der Benutzer die Aktualisierung der anderen Felder in der Zeile.

code-behind:

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

    GridViewRow row = GridView1.Rows[e.RowIndex];

    String d1 = ((TextBox)(row.Cells[2].Controls[0])).Text;
    String d2 = ((TextBox)(row.Cells[3].Controls[0])).Text;

    //this only works while the field is not readonly      
    string prIDUpdate = ((TextBox)(row.Cells[1].Controls[0])).Text; 

}

Hinweis: ich habe versucht mit GridView1.DataKeys[e.RowIndex] und auch onRowDataBound d Einstellung der BoundField bereit, nur in der code-behind-aber ich habe nicht in der Lage, um Ergebnisse zu erhalten

Vielen Dank im Voraus!

InformationsquelleAutor Poorya | 2013-11-08

Schreibe einen Kommentar