我正在尝试将 GridView 中的记录模式更改为“编辑模式”,即当用户单击 GridView 中的编辑按钮以编辑特定记录时。
我使用以下代码:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
SqlConnection con = new SqlConnection("Data Source=MEHDI-PC\\SQLEXPRESS;Initial Catalog=PIMS;Integrated Security=True");
string sql = "select [DwgRegID],[Ref],[Dwg_Ref],[Title],[Dwg_Received_Date],[Rev],[Trade],[Type],[Produced_Date],[Produced_By],[Submittal_Ref],[Issued_To],[Date_Issued],[Purpose],[Status],[Action_Date] from dbo.Dwg_Register where [DwgRegID]=N'" + GridView1.Rows[e.NewEditIndex].Cells[1].Text + "'";
con.Open();
SqlDataAdapter adp = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
adp.Fill(ds);
if (con != null)
{
con.Close();
}
GridView1.DataSource = ds;
GridView1.DataBind();
但它不起作用。程序只是把我从 EDITRECORD 视图扔到主视图。
Gridview结构(.aspx)如下:
GridView 结构部分是:
<asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowEditing="GridView1_RowEditing" DataKeyNames="DwgRegID" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowUpdated="GridView1_RowUpdated" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
请帮忙。
问候