Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2.0 GridView

Status
Not open for further replies.

rravenn

Programmer
Jul 6, 2004
40
US
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 is zero, I cnanot update anything. What's wrong with that?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top