1、取值:
protected void Button1_Click(object sender, EventArgs e) { string str = ""; foreach (GridViewRow row in this.GridView1.Rows) { str += ((Label)row.FindControl("Label2")).Text + ","; str+= row.Cells[0].Text.ToString(); } }
2、
<script runat="server"> void AuthorsGridView_SelectedIndexChanged(Object sender, EventArgs e) { String lastName = selectRow.Cells[1].Text; // 针对BoundField字段 DataBoundLiteralControl firstNameLiteral = (DataBoundLiteralControl)selectRow.Cells[2].Controls[0]; //针对TemplateField字段 String firstName = firstNameLiteral.Text; } </script> <asp:gridview id="AuthorsGridView" datasourceid="AuthorsSqlDataSource" autogeneratecolumns="false" autogenerateselectbutton="true" onselectedindexchanged="AuthorsGridView_SelectedIndexChanged" runat="server"> <columns> <asp:boundfield datafield="au_lname" headertext="Last Name"/> <asp:templatefield headertext="FirstName"> <itemtemplate> <%#Eval("au_fname")%> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
3、
时间: 2024-11-04 12:37:53