Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate row in GridView does not work
    primarykey
    data
    text
    <p>I am using gridview to represent data in asp.net, but when I click on update link nothing happens.When I trace the code I found the page reload without entering update method. Also, I am trying to solve this problem in different ways, but no luck.</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/ins.Master" AutoEventWireup="true" CodeBehind="ins_topic2.aspx.cs" Inherits="RFID_SAMS.ins_topic2"%&gt; &lt;asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit" AllowPaging="true" DataKeyNames="Week#/Day"&gt; &lt;Columns&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID="btnedit" runat="server" CommandName="Edit" Text="Edit"/&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;asp:LinkButton ID="btnupdate" runat="server" CommandName="Update" Text="Update" /&gt; &lt;asp:LinkButton ID="btncancel" runat="server" CommandName="Cancel" Text="Cancel"/&gt; &lt;/EditItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>and the code behind is:</p> <pre><code>protected void Page_Init(object sender, EventArgs e) { try { connetionString = "Server=petunia.arvixe.com;Database=rfid-sams;User Id=rfid-sams-admin;Password=10100;MultipleActiveResultSets=true"; cnn = new SqlConnection(connetionString); cnn.Open(); }//end try connection catch (Exception ex) { Response.Write(ex); } } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { View_lectures_topic(); } }// end page_load protected void View_lectures_topic() { week_num = 1; DataTable table = new DataTable(); DataRow dr; table.Columns.Add("Week#/Day"); table.Columns.Add("Saturday"); table.Columns.Add("Sunday"); table.Columns.Add("Monday"); table.Columns.Add("Tuesday"); table.Columns.Add("Wednesday"); for (int i = 1; i &lt; 17; i++) { dr = table.NewRow(); dr[0] = "Week " + i; table.Rows.Add(dr); } for (int i = 0; i &lt; 16; i++) { query1 = "select * from [M].[Lecture] where [sec_no] = '" + section + "'AND [week_no]='" + week_num + "' Order by [date];"; checkuser1 = new SqlCommand(query1, cnn); rdr1 = checkuser1.ExecuteReader(); while (rdr1.Read()) { date = Convert.ToDateTime(rdr1["date"].ToString()); day = (int)date.DayOfWeek; day = day + 2; if (day == 1 || day == 8) { sat = true; table.Rows[i][1] = rdr1["topic"].ToString(); } }//end while week_num++; }//end for loop GridView1.DataSource = table; GridView1.DataBind(); } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; View_lectures_topic(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; string week; //week = row.FindControl("Week#/Day").ToString(); week = row.Cells[0].Controls[0].ToString(); query1 = "select * from [M].[Lecture] where [sec_no] = '" + section + "' AND [week_no]='" + week + "' Order by [date];"; checkuser1 = new SqlCommand(query1, cnn); rdr1 = checkuser1.ExecuteReader(); SqlCommand cmd; while (rdr1.Read()) { date = Convert.ToDateTime(rdr1["date"].ToString()); day = (int)date.DayOfWeek; day = day + 2; if (sat == true &amp;&amp; (day == 1 || day == 8)) { cmd = new SqlCommand("UPDATE [M].[Lecture] set [topic]='" + row.Cells[1].Controls[0].ToString() + "' where [date]='" + rdr1["date"].ToString() + "' AND [sec_no]='" + section + "';", cnn); cmd.ExecuteNonQuery(); }// end if }// end while GridView1.EditIndex = -1; //call binding method View_lectures_topic(); }// end method </code></pre> <p>Could you please help me to solve this problem?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload