Solved

edit delete programatically

Posted on 2009-03-31
4
326 Views
Last Modified: 2012-05-06
r.CssClass = "prgdata"
            c = New TableCell
            c.Text = "<input type=submit  value=Edit&nbsp;Quantity />"
            r.Cells.Add(c)

            r.CssClass = "prgdata"
            c = New TableCell
            c.Text = "<input type=submit  value=Delete />"
            r.Cells.Add(c)

Visual studio 2003 1.1 frameworks

Yes I am not to sure on how to have a functional edit update and delete button programatically.
When I choose edit the Quantity should become a textbox and then I will update. Binded no problem, programatically a problem.

Dim sqlDR As SqlDataReader
        conn.Open()
        sqlDR = cmd.ExecuteReader(CommandBehavior.Default)
       
 
        ' While sqlDR.Read
        r = New TableRow
        r.CssClass = "HeaderCell"
        r.Style.Add("background", "339300")
        r.Style.Add("color", "FFFFFF")
        ' r.Style.Add("color", "Black")
        c = New TableCell
        c.ColumnSpan = 5
 
        c = New TableCell
        c.Text = "UPC code"
        r.Cells.Add(c)
 
        c = New TableCell
        c.Text = "Product Name"
        r.Cells.Add(c)
 
        c = New TableCell
        c.Text = "Quantity"
        r.Cells.Add(c)
 
        c = New TableCell
        c.Text = "Subtotal"
        r.Cells.Add(c)
 
        c = New TableCell
        'c.Text = "Case"
        r.Cells.Add(c)
 
        c = New TableCell
        'c.Text = "pallet"
        r.Cells.Add(c)
 
        'c = New TableCell
        'c.Text = "Trailer"
        'r.Cells.Add(c)
 
        Table1.Rows.Add(r)
        ' End While
 
 
        While sqlDR.Read
 
           
            r = New TableRow
            c = New TableCell
 
            r.CssClass = "prgdata"
            c = New TableCell
            c.Text = sqlDR("myItem")
            r.Cells.Add(c)
 
            r.CssClass = "prgdata"
            c = New TableCell
            c.Text = sqlDR("Name")
            r.Cells.Add(c)
            Table1.Rows.Add(r)
 
            r.CssClass = "prgdata"
            c = New TableCell
            c.Text = sqlDR("Quantity")
            r.Cells.Add(c)
 
            r.CssClass = "prgdata"
            c = New TableCell
            c.Text = FormatPrice778(sqlDR("SubTotal"))
            r.Cells.Add(c)
 
            r.CssClass = "prgdata"
            c = New TableCell
            c.Text = "<input type=submit  value=Edit&nbsp;Quantity />"
            r.Cells.Add(c)
 
            r.CssClass = "prgdata"
            c = New TableCell
            c.Text = "<input type=submit  value=Delete />"
            r.Cells.Add(c)
 
            r.CssClass = "prgdata"
            c = New TableCell
            c.Text = "&nbsp;"
            r.Cells.Add(c)
 
           
            
            If sqlDR("BalanceQty") = "0" Then
 
                c.Text = "&nbsp;"
 
            Else
              
                Table1.Rows.Add(r)
                r = New TableRow
                c.Text = "&nbsp;"
                r.Cells.Add(c)
 
                c = New TableCell
                c.Text = "Cases"
                r.Cells.Add(c)
 
                r.CssClass = "prgdata2"
                c = New TableCell
                c.Text = sqlDR("BalanceQty")
                r.Cells.Add(c)
 
                r.CssClass = "prgdata2"
                c = New TableCell
                c.Text = FormatPrice778(sqlDR("CaseCost"))
                r.Cells.Add(c)
 
                r.CssClass = "prgdata2"
                c = New TableCell
                c.Text = "&nbsp;"
                r.Cells.Add(c)
 
            End If
 
            If sqlDR("TotalPalletQty") = "0" Then
 
                c.Text = "&nbsp;"
 
            Else
                Table1.Rows.Add(r)
                r = New TableRow
                c.Text = "&nbsp;"
                r.Cells.Add(c)
 
                c = New TableCell
                c.Text = "Pallet"
                r.Cells.Add(c)
 
                r.CssClass = "prgdata2"
                c = New TableCell
                c.Text = sqlDR("TotalPalletQty")
                r.Cells.Add(c)
 
                r.CssClass = "prgdata2"
                c = New TableCell
                c.Text = FormatPrice778(sqlDR("PalletCost"))
                r.Cells.Add(c)
 
                r.CssClass = "prgdata2"
                c = New TableCell
                c.Text = "&nbsp;" 'FormatPrice778(sqlDR("PalletCost"))
                r.Cells.Add(c)
 
            End If
 
 
            If sqlDR("TotalTrailerQty") = "0" Then
                c.Text = "&nbsp;"
            Else
                Table1.Rows.Add(r)
                r = New TableRow
                c.Text = "&nbsp;"
                r.Cells.Add(c)
 
                c = New TableCell
                c.Text = "Trailer"
                r.Cells.Add(c)
 
                r.CssClass = "prgdata2"
                c = New TableCell
                c.Text = sqlDR("TotalTrailerQty")
                r.Cells.Add(c)
 
                r.CssClass = "prgdata2"
                c = New TableCell
                c.Text = FormatPrice778(sqlDR("Trailer"))
                r.Cells.Add(c)
            End If
            Table1.Rows.Add(r)
 
           
 
        End While

Open in new window

0
Comment
Question by:sevensnake77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Expert Comment

by:vavjeeva
ID: 24031628
instead of adding each row in the buttion, you could use DATAGRID control and bind the data source along with the button..

you can use BoundColumn property for binding these values and use Template Column for adding button..

this links helps u to understand the core functionality of datagrid
http://www.codersource.net/asp_net_datagrid_part1_azam.html
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24031764
Yes I know how to do that, I said that in my comment above, Thats why i was asking to do it programatically because I had no choice.
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24032517
somthing like i have below.

 r.CssClass = "prgdata"
            c = New TableCell
            selectcol.ButtonType = ButtonColumnType.PushButton
            selectcol.Text = "Update"
            selectcol.CommandName = "Update"
            r.Cells.Add(c)
            'Table1.Rows.Add(selectcol)
            ' DataGrid1.Columns.Add(selectcol)

Open in new window

0
 
LVL 9

Accepted Solution

by:
AsishRaj earned 500 total points
ID: 24035005
How about this

<%@ Page Language="C#" %>
<script runat="server">
    
 
    void btn_Click(object sender, EventArgs e)
    {
                 Response.Write(((sender)as Button).Text);
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
      HtmlTable myTable = new HtmlTable();
        for (int i = 0; i < 4; i++)
        {
                HtmlTableRow row = new HtmlTableRow();
                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.InnerText = "cell" + i;
                row.Controls.Add(cell1);
                HtmlTableCell cell2 = new HtmlTableCell();
                Button btn = new Button();
                btn.Text = "value" + i;
                btn.Click += new EventHandler(btn_Click);
                cell2.Controls.Add(btn);
                row.Controls.Add(cell2);
                myTable.Controls.Add(row);
            
        }
        PlaceHolder1.Controls.Add(myTable);
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>untitled</title>
</head>
<body  >
    <form id="form1" runat="server" name="someForm" >
    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
   
    </form>
</body>
</html>

Open in new window

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question