Click to See Complete Forum and Search --> : Problems on GridView


dummyagain
December 16th, 2006, 09:29 AM
I have problems on using gridview.

I have several problems.
First, I cannot add columns.

Second, I choose the edit function, it allows me to edit, however, it doesn't update the record after i confirmed the change.

Here is my code

<asp:GridView id="test" runat="server" DataSourceID="source" AutoGenerateEditButton="True" AutoGenerateDeleteButton="True" AutoGenerateSelectButton="True">
<Columns>
<asp:BoundField DataField="name" HeaderText="Name" />
</Columns>
</asp:GridView>
<asp:SqlDataSource
id="source"
SelectCommand="SELECT * FROM tbl_test WHERE active = '1'"
UpdateCommand="UPDATE tbl_test SET name=@name WHERE uid=@uid"
runat="server" DeleteCommand="delete from tbl_test where uid=@uid" InsertCommand="insert into tbl_test (name) values (@name)">
<DeleteParameters>
<asp:Parameter Name="uid" Type="Int64" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="uid" Type="Int64" />

</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="name" Type="String" />

</InsertParameters>
</asp:SqlDataSource>


Thank you

jasonli
December 18th, 2006, 08:24 AM
For the first problem, You set data source of GridView to a SqlDataSource may be the reason. Actually, I think you could add any BoundField or TemplateField in designtime if you don't set AutoGenerateColumns to true.

About update, you are trying to update by SqlDataSource. I'm not sure how to update by SqlDataSource 'cause I never use that. I'd like to update programmatically. You can't get anything without coding.

Hope it helps.