So I've got to learn ASP.Net and C# for work. The organisation has bought in some training and some books. I'm using the books and the web ahead of the training next month.
Presently I have worked through some tutorials online and in the books. I've got a basic handle on C# now and am working on some mock projects for ASP.Net. A good friend of mine , pointed me in the direction of the GridView as a very useful tool. I must agree this is very useful and I can see the benefits of it.
However, I feel I must be missing something with this as the code I have so far looks like:
My issue with this is the mixing of the view and model layers. Surely I've got something wrong here right?
I had spent some time developing a simple Data Abstraction Layer to make a connection and issue queries. This used the Web config file and can be usedvery easily.
So, the point of all this rambling is to ask the question can the update and delete command be housed at the very least in the code behind file? I feel really uncomfortable having the code where it is.
I have tried another approach that I feel is heading in the right direction:
The data is then bound in the code file usnig OdbcAdapter and OdbcCommand and this presents the data but I'm not getting the built in edit and delete functionality so I need to know what events I need to write or how to make sure the events I want to fire anre fired.
If anyone has any help on this that would be great, perhaps point me in the right direction.
Cheers
nathj
Presently I have worked through some tutorials online and in the books. I've got a basic handle on C# now and am working on some mock projects for ASP.Net. A good friend of mine , pointed me in the direction of the GridView as a very useful tool. I must agree this is very useful and I can see the benefits of it.
However, I feel I must be missing something with this as the code I have so far looks like:
Code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MySQLConnStr %>" ProviderName="<%$ ConnectionStrings:MySQLConnStr.ProviderName %>" SelectCommand="SELECT a.id, a.name, a.country from test_users a" UpdateCommand="UPDATE test_users SET name=@name, country=@country WHERE id=@id" DeleteCommand="Delete from test_users where id = @id"> <UpdateParameters> <asp:Parameter Name="name" Type="String" /> <asp:Parameter Name="country" Type="String" /> <asp:Parameter Name="id" Type="Int32" /> </UpdateParameters> <DeleteParameters> <asp:Parameter Name="id" Type="Int32" /> </DeleteParameters> </asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server" PageSize="4" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="id" HeaderText="id" SortExpression="id" InsertVisible="False" ReadOnly="true" /> <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" /> <asp:BoundField DataField="country" HeaderText="country" SortExpression="country" /> <asp:CommandField ButtonType="Image" DeleteImageUrl="~/image/delete.png" EditImageUrl="~/image/edit.png" ShowDeleteButton="True" ShowEditButton="True" /> </Columns> </asp:GridView>
I had spent some time developing a simple Data Abstraction Layer to make a connection and issue queries. This used the Web config file and can be usedvery easily.
So, the point of all this rambling is to ask the question can the update and delete command be housed at the very least in the code behind file? I feel really uncomfortable having the code where it is.
I have tried another approach that I feel is heading in the right direction:
Code:
<asp:GridView ID="grd_userList" runat="server" AllowSorting="false" AllowPaging="false" AutoGenerateColumns="true" AutoGenerateDeleteButton="true" AutoGenerateEditButton="true" AutoGenerateSelectButton="true" OnRowWEditing="grd_userList_edit" />
If anyone has any help on this that would be great, perhaps point me in the right direction.
Cheers
nathj
Comment