简体   繁体   中英

Add autogenerated Column to gridview

i have AutoGenrated SerialNo of my Gridview in RowDatabound event like below..

 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();
            }
        }

Now i Want to Add this Text to my SQL Column..this SeirlNo is first Column ,,i followed Below procedure to add the values to the Sql Table...

 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='"++"');

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

But here i strucked..i fogotted that SerialNo is autogenrated..how wud i get the SerialNo value here???? Give me some valuable suggestions plz...

        }

Add a public property to hold the value of the Serial No when it is generated. Then pass that value into your sqlCommand

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM