[RESOLVED] how to cerated validation control dynamically and apply for dynamically created control

Hi,I am working on asp.net,my task is,creating control dynamically, in page i have created only one row,i have dropdownlist,3 TextBoxes,in first drop down i have category,second dropdown i have information,remaining 2 textboxes i am entering values,i am calling this method on every page  load,when i clcik + image i am adding another row,when i clicked Minus,i am removing oner row,if ok, when i click the save button,i need do the validation by using validation control.how i can created required field validator dynamically,how i can apply when i click the save button,i have plus button,minus buttotn,dropdown selected index chnged ,can any onr reply to plhkrishna@hotmail.com

Hi

When you add the textbox, add Validator below:

For example:

input = new TextBox();
            input.ID = "id";
            this.Controls.Add(input);

            validate = new RequiredFieldValidator();
            validate.ID = "valid";
            validate.ControlToValidate = input.ID;
            validate.ErrorMessage = "require";
            validate.Display = ValidatorDisplay.Dynamic;
            this.Controls.Add(validate);


<div class="entry">
TextBox objtext = new TextBox();
Page.Form.Controls.Add(objtext);
RequiredFieldValidator objReq = newRequiredFieldValidator();
objtext.ID = "MyTextBox";
objReq.ControlToValidate = objtext.ID;
objReq.ErrorMessage = "Please tell us some thing";
Page.Form.Controls.Add(objReq);
<div>
</div> </div>

[RESOLVED] find the controls in the gridview if the gridview.rows.count=o

I have designed a gridview in the aspx page.In the Code Behind I could not find controls in the gridview because the gridview.rows.count=o as the gridview is not binded before.

How do i find the controls in the gridview if the  gridview.rows.count=o?

Which event you are using to write the find control code?

after binding only u can get the data...before it will be 0 only know....!

after binding the data to gridview , try to count!

all the best!

sudhir.kathuria

Which event you are using to write the find control code?

 Dim tb As Label = DirectCast(Grd_List_of_Values.Rows(i).Cells(1).FindControl("lblID"), Label)

But i need to add the dataset set values to the labels,textboxes in a gridview on button_click.

BUT THESE LABELS,TEXTBOXES ARE EMPTY ITEM  TEMPLATES

I advise you to google/bing gridview and learn how it works. The general idea is that you set a template of what the GV will look like, and then you databind it to a DataSource to fill the contents. Might check this: http://msdn.microsoft.com/en-us/library/bb288032.aspx. Or search for other pages.

[RESOLVED] Help needed with getting an unspecified amount of data

Hiya,

I am a fairly new developer with ASP.NET so apologies if this is in the wrong forum.

I am creating a booking system which takes the number of people on the and stores it into a database table. I then need to store specific data about each person on the trip, name, contact number etc. The idea is that once they have specified the amount of people (looking at a max of 8 per trip probably) they get greated with a page requesting the details, with the numbers parsed as a query string. What would be the best way to do it, and how? 

I investigated using a HTML table but this looked untidy and would rather use something like a repeater, but wouldn't know how to start with using a repeater with a query string.

Thanks in advance!

Dear StereoRoyal,

Based on your requirement i would create a user control which contains the specific data about each person (trip, name, contact number, etc) and depending upon the number which is sent as query string/session variable from the other page, i would loop this user control to load as wizard control for that many times with status of the number of people inserted after each loop.

If you find this way suitable, please follow this and ask me for more clarification. 

Create Repeater control on ASPX page as shown in below sample code:

<asp:Repeater runat="server" ID="myRepeater" >
            <HeaderTemplate>
                <table width="90%" align="center" border="1">
                    <tr>
                        <th>Category</th>
                        <th>Gender</th>
                        <th>No_Of_Files</th>
                        <th>QueryString Value</th>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td><%# DataBinder.Eval(Container, "DataItem.Category")%></td>
                    <td><%# DataBinder.Eval(Container, "DataItem.Gender")%></td>
                    <td><%# DataBinder.Eval(Container, "DataItem.No_Of_Files")%></td>
                    <td>The QueryString value is <%=Request.QueryString["my_querystring_parameter"] %></td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

In th CS file:

    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable objDT = new DataTable();

        objDT.Columns.Add("Category");
        objDT.Columns.Add("Gender");
        objDT.Columns.Add("No_Of_Files");

        objDT.Rows.Add("Indian", "M", "2");
        objDT.Rows.Add("American", "F", "5");
        objDT.Rows.Add("American", "M", "4");
        objDT.Rows.Add("Indian", "F", "3");

        myRepeater.DataSource = objDT;
        myRepeater.DataBind();
    }

Now run the application. In the browser, pass QueryString to your page as:

http://~/your_page.aspx?my_querystring_parameter='My Value'

What say for Inline Create/Edit light Weight Grid using JQuery - http://www.trirand.com/blog/ 

Create the number of rows which you get in query string, then fill in the details in the jquery grid...

The reason why I am recommending this grid was, large data entry can be easy with simple and quick inline grid...you can quickly navigate through the cells using TAB button of keyboard...

Thanks, 

Having created my user control, I am now getting it to display on screen. 

This is my user control:

<table class="style1">
<tr>
<td class="style2" width="50">
<asp:Label ID="Label1" runat="server" Text="Adult Name"></asp:Label>
</td>
<td width="50">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
</table>

And this is how I am adding the control to the wizard:


protected void Page_Load(object sender, EventArgs e)
    {
       for (int i = 0; i < 5; i++)
        {
            WizardStepBase newStep = new WizardStep();
            GetAdultData adults = new GetAdultData();
            newStep.Controls.Add(adults);
            Wizard1.WizardSteps.Add(newStep);
        }
}
Yet it is not displaying properly. 

I prefer to go for a Javascript functions where create the rows dynamically and you always have option to save the values to the DB.

Here is the javascript code

-------

function

addRow(tableID) {

var

table = document.getElementById(tableID);

var rowCount = document.getElementById('MainContent_txtNoOfPersons'

);

if

(rowCount.value <= 0) {

alert(

"Please Enter No. Of Passengers to be Added@!"

);

return false

;

}

//delete all rows and then insert again

var

rows = table.rows.length;

for (var

i = rows; i > 0; i--) {

table.deleteRow(i-1);

}

for

(i = 0; i < rowCount.value; i++) {

var

row = table.insertRow(i);

var

cell1 = row.insertCell(0);

var element1 = document.createElement("input"

);

element1.type =

"checkbox"

;

cell1.appendChild(element1);

var

cell2 = row.insertCell(1);

cell2.innerHTML = i + 1;

var

cell3 = row.insertCell(2);

var element2 = document.createElement(<span style="font-family: Consolas; color: #800000; font-size: x-small;" face="Consolas" size="2" col

I prefer to go for a Javascript functions where create the rows dynamically and you always have option to save the values to the DB.

Here is the javascript code

-------

function

addRow(tableID) {

var

table = document.getElementById(tableID);

var rowCount = document.getElementById('MainContent_txtNoOfPersons'

);

if

(rowCount.value <= 0) {

alert(

"Please Enter No. Of Passengers to be Added@!"

);

return false

;

}

//delete all rows and then insert again

var

rows = table.rows.length;

for (var

i = rows; i > 0; i--) {

table.deleteRow(i-1);

}

for

(i = 0; i < rowCount.value; i++) {

var

row = table.insertRow(i);

var

cell1 = row.insertCell(0);

var element1 = document.createElement("input"

);

element1.type =

"checkbox"

;

cell1.appendChild(element1);

var

cell2 = row.insertCell(1);

cell2.innerHTML = i + 1;

var

cell3 = row.insertCell(2);

var element2 = document.createElement("input"

);

element2.type =

"text"

;

cell3.appendChild(element2);

}

return false

;

}

----------------

HTML Code

-------------

<asp:Label ID="lblNoOfPersons" Text="No.Of Passengers" runat="server"></asp:Label

>

<asp:TextBox ID="txtNoOfPersons" runat="server"></asp:TextBox>&nbsp;<asp:Button ID="btnGenerate" runat="server" Text="Generate Table" OnClientClick="javascript:addRow('tblPassengerDetails'); return false;"

/>

<table id

='tblPassengerDetails'>

</table

>

-------------

Let me know if that solves the problem.

Hi everyone,

Thanks for all your help. The solution I have come up with is to use 2 placeholders for the two types of guest and simply add the controls using a For loop depending on how many are required. I can then get the data using the FindControl command.

[RESOLVED] Shift logic test

I needed bit help in coding for the following scenario

Scenario:-

We have to take an integer value as an input(like 123,356 etc) if the left most no is lesser than the no to its right it has to display it as an absolute no. I know some where i have to use array logic but i m not getting how. Any help will be deeply appreciated.

Regards

Harsha D

Sry for putting out such a silly post. I was thinking in complex way but solution was very simple which uses the simple logic of reverse of a no. Any way apologies

pls check this.....


 string value = "123456";

        char first = value[0];
        char last = value[value.Length - 1];

        if (first <= last)
        {
            //display
            Response.Write("absolute");
        }


[RESOLVED] How to Open a tab in a multiview

Hi all i want to do is:

onclick the button.......the view of the multiview  control should dispalyed just as a new tab is shown with the previous view of the multiview...

The detail is: 

I am using a multiview in my website..........All i need is whenever a button is clicked in a view of the entire miltiview control.....instead of opening the resultend page on the other window.....i want to open a (tab like) view  in multiview that displays the result while the previous view remains open ......how would i can acheive this

I am not sure if i understood your question properly, but i think you need tab control of some sort...so I am proposing AJAX Tab Container...http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/Tabs/Tabs.aspx 

Thanks,

Refering to your provided link let me clear my question:

As you can see in your link that there are 3 tabs namely (1)Signature & Bio (2)Email (3)Controls ............now friend what i need is...............

As there is a Save button in the "Signature & Bio" tab.... all i need is to have the same thing but in a manner that firstly only the "Signature & Bio" tab should be appeared than after clicking the Save button the second tab should be appeared of Email..................and so on

Hope i am able to clarify my question.....

mmazeemahmad

As there is a Save button in the "Signature & Bio" tab.... all i need is to have the same thing but in a manner that firstly only the "Signature & Bio" tab should be appeared than after clicking the Save button the second tab should be appeared of Email..................and so on

I think ASP.Net Wizrd works for you - http://www.codeproject.com/KB/aspnet/Wizard_Control.aspx 

Thanks,

hi,

in pageload:

set multiview1.ActiveIndex=0;

and in save button write:

multiview1.ActiveIndex=1;

and so on......

Otherwise if u have the knowledge of JQuery, it becomes more simple. As View and Multiview are asp.net controls, postback will occur each and every time. So to avoid this, try to use JQuery Tabs.

All the best!

Dear  shiva.ram24 i want to hide all of the view's when page load and than onclicking any button i want to show those views as tabs with the previous views..............that's it............kindly tell me the full solution for it...................

Dear ramiramilu this wasn't what i needed kindly guide me little more.....

Ofcourse u can do that...

just do..

View1.Visible = false;

I think it will work surely!

Dear shiva.ram24 if u can provide me some demo code than i would be ery thankful to you...............

        <asp:MultiView ActiveViewIndex="0" runat="server" ID="MultiView1">
<asp:View ID="ViewLand" runat="server">
<asp:Button Text="save" runat="server" ID="btnSave" onclick="btnSave_Click"/>
</asp:View>
<asp:View ID="View1" runat="server">
<asp:Button Text="Register" runat="server" ID="btnRegister"
onclick="btnRegister_Click"/>
</asp:View>
<asp:View ID="View2" runat="server">
<asp:Button Text="SignUp" runat="server" ID="btnSignUp" onclick="btnSignUp_Click"/>
</asp:View>
</asp:MultiView>

        protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MultiView1.ActiveViewIndex = 0;
}
}

protected void btnSave_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 1;
}

protected void btnRegister_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 2;
}

protected void btnSignUp_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 0;
}

All the best!

Hi shiva.ram24 your code doesn't open up the view in a new tab instead of it, it replaces the current one and opens in the same window instead of opening in a new tab...............

                <asp:HyperLink NavigateUrl="WebForm1.aspx" runat="server"  onclick="NewWindow()" Text="clickNew window"/>

    <script type="text/javascript">

function NewWindow() {
window.open("WebForm1.aspx");
alert("new window");
}
</script>

follow this link

http://www.dotnetcurry.com/ShowArticle.aspx?ID=178

http://dheerajstechwiki.blogspot.com/2009/12/dynamically-adding-tab-panels-into.html

Dearshiva.ram24

i think that i was unable to clarify my problem.............i want to open a (tab like) view  in multiview that displays the result while the previous view remains open ......but not to open a new tab in my browsers window

follow this link

http://www.dotnetcurry.com/ShowArticle.aspx?ID=178

Yap eworker1 your suggested solution is excellent and did worked, before marking your post as answer kindly tell me the last thing that i want to add the close image on each tab so that user can able to close the tab by clicking on that image would u have any suggestions about it????

ok i have done all the things and now only needs a code to close the current tab of tabcontainer..............i am using an imagebutton and want to write a code behind it to get the tab close or hide....