ASP.NET 2 GridView.

R

realgeek

I got to playing with ASP.NET 2.0. So I have the following code:
CODE
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="QuestionID"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:BoundField DataField="Description"
HeaderText="??????"></asp:BoundField>
<asp:CheckBoxField DataField="IsActive" HeaderText="???." />
<asp:CommandField ButtonType="Image"
CancelImageUrl="img/button_cancel.png" EditImageUrl="img/edit.png"
ShowEditButton="True" UpdateImageUrl="img/button_ok.png" />
</Columns>
</asp:GridView>


In .cs file:
CODE
SqlDataSource ds;

protected void BindData()
{
ds = new
SqlDataSource(WebConfigurationManager.ConnectionStrings["AnketaDBConnectionString"].ToString(),
"SELECT QuestionID,Description,IsActive FROm Question");
GridView1.DataSource = ds;
GridView1.DataBind();

}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}

protected void GridView1_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
Response.Write(e.Keys.Count.ToString());
Response.Write(e.NewValues.Count.ToString());
}

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

protected void GridView1_RowCancelingEdit(object sender,
GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindData();
}

You see that it outputs number of keys and new values on update.
Problem is, both numbers are zero when I press edit, preform editing
and press ok, I cannot update anything. What's wrong with that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top