Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
 
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" >
        	        <HeaderTemplate>
        	            <table >
        	                <thead><tr>
                                      <th>Terminal Tab</th>
			              <th>Terminal Attributes</th>
			              <th>Values
                                 </th></tr></thead>
        	                <tbody>
        	        </HeaderTemplate>
        	        <ItemTemplate>
			        <tr>
				   <td><%# Eval("TabName") %></td>
			           <td><%# Eval("TagName") %></td>
				   <td><%# GenerateTag(Eval("Datatype"))%></td>
			        </tr>
        	        </ItemTemplate>
        	        <FooterTemplate>
        	            </tbody>
        	            </table>
        	        </FooterTemplate>
        	    </asp:Repeater>
        	
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  />";
                    break;
                case "Int":
                    strTags = "<input id=tagInt type=text  />";
                    break;
                case "Boolean":
                    strTags = "<input id=cbx type=checkbox  />";
                    break;
                default:
                    strTags = "<input id=strInput type=text />";
                    break;
            }
            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);
            myRepeater.DataBind();
 

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                    10.1.1.2
         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                    10.2.2.2
         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 9:33am
guodl544
Edited 3-Jan-13 9:44am
v4

1 solution

Rate this: bad
good
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 // ...
    // ...
    else
        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..." Smile | :)
 
—SA
  Permalink  

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



Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
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