Click here to Skip to main content
13,296,823 members (38,680 online)
Rate this:
Please Sign up or sign in to vote.
See more:

Please enlight me how to insert/update/delete records based on generated textbox/checkbox.

I used the following code to generate the textbox/checkbox:

<asp:Repeater ID="myRepeater" runat="server" >
                      <table >
                                    <th>Terminal Tab</th>
                        <th>Terminal Attributes</th>
                 <td><%# Eval("TabName") %></td>
                     <td><%# Eval("TagName") %></td>
                 <td><%# GenerateTag(Eval("Datatype"))%></td>

Below is the function of GenerateTag:
        /// <summary>
        /// Generate tages based on data type.
        /// </summary>
        /// <param name="objDataType"></param>
        protected string GenerateTag(object objDataType)
            String strTags = "";
            switch (objDataType.ToString()) {
                case "Char":
                    strTags = "<input id=tagText type=text  />";
                case "Int":
                    strTags = "<input id=tagInt type=text  />";
                case "Boolean":
                    strTags = "<input id=cbx type=checkbox  />";
                    strTags = "<input id=strInput type=text />";
            return strTags;

I use the following SQL statement in myRepeater:

           string strSQL = @"
                   Select       T.ID
                              , T.TabID  TabID
                              , Tab.Name TabName
                              , T.TagName
                              , T.AppID
                              , T.DataType
                              , T.MinLen
                              , T.MaxLen
                              , A.Name AppName
                              , T.Description
                   From TerminalAttrTag T 
                         Left Join TerminalAttrApp A   on T.AppID = A.ID 
                         Left Join TerminalAttrTab Tab on T.TabID = Tab.ID     
                               Where T.AppID = {0} or T.AppID = 1 
                               Order by T.TabID, T.SeqNo
            strSQL = String.Format(strSQL, AppID);
            myRepeater.DataSource = bl.GetDataSet(ConnectionString, strSQL);

In screen, it shows:

         Terminal Tab                Terminal Attributes         Values
         Host Config                 Host Name                  (Textbox)
         Host Config                 Host IP                    (Textbox)
         Host Config                 Timeout                    (Textbox)

I can input below info:

         Terminal Tab                Terminal Attributes         Values
         Host Config                 Host Name                  Machine1
         Host Config                 Host IP          
         Host Config                 Timeout                    30 

Now I want to be able to click "Add" button to input below record (2nd records).

         Terminal Tab                Terminal Attributes         Values
         Host Config                 Host Name                  Machine2
         Host Config                 Host IP          
         Host Config                 Timeout                    50

I am thinking to use DetailsView but in the end I give up due to the dynamic generated textbox.

1. Please enlight me how I can add code in 'Add' button to insert records. Or which part of code need to be fixed or rewrite? And please advise the suitable way to handle this.

2. After problem of add/delete/update records solved, please enlight me how to loop through the records. I need to save all records to database or xml files.

Thank you for your patient.
Posted 3-Jan-13 10:33am
Updated 3-Jan-13 10:44am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Sorry for not answering the question, but one caught fragment made a really strong pain in my eyes. I mean switch statement with objDataType.ToString().

I cannot stand it. How anyone can write such things? First of all, this is a really fatal trend to work with string representation of data instead of data itself. And also, two completely different types can return the same string by ToString(). In the very worst case, all you need is this:
protected string GenerateTag(System.Type objectType) { // not object!
    if (objectType == typeof(System.Boolean))
        return // ...
    // ...
        return //...
    // I wanted to write what to return, but noticed that you also violate HTML syntax. You should not omit ""!

Don't want to continue as I'm not sure that your whole idea is right...

I want to say: "and so on..." :-)


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171207.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100