【发布时间】:2013-07-10 11:58:33
【问题描述】:
我正在尝试将 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>
请帮助。
问候
【问题讨论】:
-
“EDITRECORD View to home-View”这是什么意思?
-
请发表gridview结构(aspx部分)
-
@TimSchmelter :我有 2 个视图( ViewHome、ViewGrid )。 home-View 包含具有不同选项的按钮,例如“插入记录”、“编辑记录”、“更新记录”等。 ViewGrid 上面有 GridView。因此,当用户单击“主视图”上的“编辑记录”时,程序会将用户带到“ViewGrid”。希望你能明白。
-
@Md.ParvezAlam:Gridview 结构部分太长,无法在此处粘贴.. 任何其他粘贴方式?
-
嘿,我认为你没有提供数据源,