GridView中的RowEditing无法正常工作

时间:2013-07-10 11:58:34

标签: c# asp.net gridview

我正在尝试将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视图扔到home-View。

Gridview结构(.aspx)如下:

GridView Structure部分是:

    <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>

请帮助。

此致

3 个答案:

答案 0 :(得分:2)

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
    GridView1.EditIndex = e.NewEditIndex;
///////////GridView1.Datasource = datasource;  // here you missing
    GridView1.DataBind(); 
}

答案 1 :(得分:1)

将EditIndex属性设置为适当的行,然后再次将GridView重新绑定到它的DataSource。

这是代码

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
   {
    GridView1.EditIndex = e.NewEditIndex;
    BindGrid();

   }

您可以阅读更多here

答案 2 :(得分:1)

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1227)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:322)
at javax.mail.Service.connect(Service.java:236)
at javax.mail.Service.connect(Service.java:137)
at javax.mail.Service.connect(Service.java:86)
at javax.mail.Transport.send0(Transport.java:150)
at javax.mail.Transport.send(Transport.java:80)
at MailSending.main(MailSending.java:45)