将自动生成的列添加到gridview

时间:2013-12-20 15:22:14

标签: asp.net gridview

我在RowDatabound事件中有我的Gridview的AutoGenrated SerialNo,如下所示..

 protected void Gdview_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblSerial = (Label)e.Row.FindControl("lblSRNO");
                lblSerial.Text = "S" + ((Gdview.PageIndex * Gdview.PageSize) + e.Row.RowIndex + 1).ToString();
            }
        }

现在我想将此文本添加到我的SQL列中..这个SeirlNo是第一列,我按照下面的步骤将值添加到Sql表...

 protected void Button1_Click(object sender, EventArgs e)
        {
            string strOrganization = txtOrganization.Text;
            string strOrigin = txtOrigin.Text;
            string strLoc = TexLocation.Text;
            string strService = TxtService.Text;
            string strEst = TxtEstablish.Text;

            //SqlCommand cmd = new SqlCommand ("Insert into mpSoftware Organization='"+strOrganization+"'",Origin='"++"',Location='"++"',Service='"++"',Est='"++"' Where SerialNo='"++"');

..... .... ...

但是在这里我震惊了......我发现SerialNo是自动生成的。我在这里得到了SerialNo值吗?给我一些有价值的建议......

        }

1 个答案:

答案 0 :(得分:0)

添加公共属性以在生成时保留序列号的值。然后将该值传递给sqlCommand