c# - Gridview Command and Selected Row -


I am trying to get the selected row data and trying to move it to a label on the same page . Although I can not get a gridview. Select to work with my CommandName I have tried everything ....

I get an error that the object is not set according to the frequency of the object. is. On Label2.Text

Here is my code:

  Protected Zero GridView1_RowCommand (Object Sender, GridViewCommandEventArgs E) {// Many ButtonField column fields are used, using / / CommandName property to determine which button was clicked. If (e.command-name == "hold") {Label2.Text = GridView1. Selected Row.Cells [2]. Text; Label3.Text = GridView1 Selected Row.Cells [3]. Text; Label4.Text = GridView1 Selected RAW Seals [4]. Text; Label5.Text = GridView1 Selected R. Kell [5]. Text; }}     
; ASP: GridView id = "GridView1" runat = "Server" AllowPaging = "True" AllowSorting = "True" AutoGenerateColumns = "false" BackColor = "White" BorderColor = "#DEDFDE" BorderStyle = "None" BorderWidth = "1px" CellPadding = "4" DataKorNames = "ID" DataSourceID = "SqlDataSource1" ForeColor = "Black" Gridlines = "Vertical" CssClass = "td" OnSelectedIndexChanged = "Gridview 1 Cylinded Index" width = "574px" onrowcommand = "Gridview 1Do Command" & gt; & Lt; AlternatingRowStyle BackColor = "White" /> & Lt; Columns & gt; & Lt; Asp: TemplateField Header Text = "Action" & gt; & Lt; ItemTemplate & gt; & Lt; asp: ImageButton id = "ImageButton2" runat = "server" ImageUrl = "~ / images / edit.png" onclic = "image button 2_Click" /> & Lt; ASP: ImageButton ID = "ImageButton1" runat = "server" commandname = "select" imageUrl = "~ / images / delete.png" onclientclick = "confirmation of return ('Do you want to remove this vehicle?');" / & Gt; & Lt; asp: ImageButton id = "ImageButton3" runat = "server" ImageUrl = "~ / images / refre.png" CommandName = "hold" /> & Lt; / ItemTemplate & gt; & Lt; / ASP: TemplateField & gt; & Lt; ASP: Boundfield datedfield = "id" headerText = "id" insert = "wrong" read oli = "true" sort campaign = "id" /> & Lt; ASP: BoundfieldDefined = "Year" Header Text = "Year" Sorted Expression = "Year" /> & Lt; ASP: Boundfield Dated Field = "Make" Header Text = "Make" Sorted Expression = "Creating" /> & Lt; ASP: BoundfieldDefined = "Model" Header Text = "Model" Sorted Expression = "Model" /> & Lt; ASP: BoundfieldDocumentfield = "Submodel" header text = "Submodel" sortExpress = "Submodel" /> & Lt; asp: BoundfieldDIFF field = "ISENABLED" header text = "ISENABLED" sorted expression = "ISENABLED" /> & Lt; / Column & gt; & Lt; FooterStyle BackColor = "# CCCC99" /> & Lt; HeaderStyle BackColor = "# 6B696B" font-bold = "true" ForeColor = "white" /> & Lt; PagerStyle BackColor = "# F7F7DE" ForeColor = "Black" Horizontal Align = "Right" /> & Lt; RowStyle BackColor = "# F7F7DE" / & gt; & Lt; Selected light backcollger = "# ce 5d5a" font-bold = "true" foreclosure = "white" /> & Lt; Sorted spacecale stylebackcroller = "#fbfbf2" /> & Lt; Sorted Header Style Style BackAllore = "# 848384" /> & Lt; SortedDending Cell Style Backlar = "#EEED3" /> & Lt; Sorted Header System Back Buckler = "# 575357" /> & Lt; / ASP: GridView & gt;    

Try something like this. Since you are trying to reach values ​​in the command event, or if not in the OnSelectedIndexChanged event, you need to catch the line that triggered the first event.

  if (e.CommandName == "hold") {GridViewRow line = (GridViewRow) ((ImageButton) e.CommandSource). NameContainer; If (line! = Null) {Label2.Text = row.Cells [2]. Text; Label3.Text = row.Cells [3]. Text; Label4.Text = row.Cells [4]. Text; Label5.Text = row.Cells [5]. Text; }}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -