Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP.NET 2 GridView.

Reply
Thread Tools

ASP.NET 2 GridView.

 
 
realgeek@gmail.com
Guest
Posts: n/a
 
      09-08-2005
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.ConnectionSt rings["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?

 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      09-08-2005
If you want to the grid to do automatic updates back to the database you
need to use the new declarative databinding model. SO, IOW, you need a <asp:SqlDataSource>
and to set the DataSourceID on your GridView.

http://beta.asp.net/QUICKSTART/aspne...a/default.aspx

-Brock
DevelopMentor
http://staff.develop.com/ballen



> 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.ConnectionSt rings["AnketaDBConne
> ctionString"].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?
>




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments