1 editable table, on one aspx page, connecting to MySQL. Can yourecommend a better way to do it the

H

hamsterchaos

I have spent 3 months and have a good functioning .net appljcaiton,
where a table is populated from the mysql database, and you can insert
and update rows.

It uses:

MYSQL
Gridview component
ODBC connection


Unfortuantely this requires ALOT of manual coding, including, stating
the parameters to be used for each of the insert, update, select
statements ( you cant use Visual Studios GUI because Im connecting to
a MYSQL database).

It also invovles recoding all of the row updating methods, insert
methods , and on top of that use complex "find" statements to figure
out which text box to gather the input from.

I include examples below:



<EditItemTemplate>
<asp:TextBox ID="finishTXT" runat="server" Text='<%#
Eval("finish") %>' />
</EditItemTemplate></asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="right"
HeaderText="Length">
<ItemTemplate ><asp:literal ID="length" runat="server" Text='<%#
formatstart(Eval("length")) %>' /></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="lengthTXT" runat="server" Text='<%#
Eval("length") %>' />
</EditItemTemplate></asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="right"
HeaderText="Room">
<ItemTemplate ><asp:literal ID="room" runat="server" Text='<%#
Eval("room") %>' /></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="roomTXT" runat="server" Text='<%# Eval("room")
%>' />
</EditItemTemplate></asp:TemplateField>

....


Name="amendmentMade" />
<asp:parameter Name="amendment" />
<asp:parameter Name="course split" />
<asp:parameter Name="group" />
<asp:parameter Name="class" />
<asp:parameter Name="banner code" />
<asp:parameter Name="person code" />
<asp:parameter Name="personcodeleadteacher" />
</InsertParameters>
<UpdateParameters>
<asp:parameter Name="day" />
<asp:parameter Name="dates" />
<asp:parameter Name="start" />
<asp:parameter Name="finish" />
....

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
Session["boobs"] = e.Row.RowIndex; ;


}
}


......


public void this_rowUpdating(Object sender,
GridViewUpdateEventArgs e)
{
int selectedrow = Convert.ToInt32(Session["boobs"]);


Box groupTXT =
(TextBox)GridView1.Rows[selectedrow].Cells[4].FindControl("TXTgroup");
TextBox classTXT =
(TextBox)GridView1.Rows[selectedrow].Cells[4].FindControl("TXTclass");
TextBox bannercodeTXT =
(TextBox)GridView1.Rows[selectedrow].Cells[4].FindControl("TXTbannercode");
TextBox personcodeTXT =
(TextBox)GridView1.Rows[selectedrow].Cells[4].FindControl("TXTpersoncode");
TextBox personcodeleadteacherTXT =
(TextBox)GridView1.Rows[selectedrow].Cells[4].FindControl("TXTpersoncodeleadteacher");



e.NewValues["day"] = dayTXT.Text;
e.NewValues["dates"] = datesTXT.Text;
e.NewValues["start"] = startTXT.Text;
e.NewValues["finish"] = finishTXT.Text;



.....


public void gridChange(Object sender, GridViewCommandEventArgs e)
{



if (e.CommandName == "Insert")
{

if (Page.IsValid)
{
TextBox txtGroup =
(TextBox)GridView1.FooterRow.FindControl("txtGroup");
TextBox txtBannerCode =
(TextBox)GridView1.FooterRow.FindControl("txtBannerCode");

if (Course.Text != null)
{

SqlDataSource1.InsertParameters["Course"].DefaultValue = Course.Text;
SqlDataSource1.InsertParameters["ID"].DefaultValue = txtId.Text;

SqlDataSource1.InsertParameters["Day"].DefaultValue = txtDay.Text;

.....


These are all examples of manual hand written code required for one
fully funciontal editable gridview in c# with mysql.

Am I being retarded? Is there a much easier way to do this?

Thanks for your time
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top