Solved

edit delete programatically

Posted on 2009-03-31
4
327 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

707 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