Search This Blog

Tuesday, December 14, 2010

Dyanmic TextBox








Aspx.cs



using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Dynamic : System.Web.UI.Page
{
static int myCount = 1;
private TextBox[] dynamicTextBoxes;


protected void Page_PreInit(object sender, EventArgs e)
{
Control myControl = GetPostBackControl(this.Page);
if (IsPostBack != false)
{
if ((myControl != null))
{
if ((myControl.ClientID.ToString() == "btnAddTextBox"))
{
myCount = myCount + 1;
}
}
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
dynamicTextBoxes = new TextBox[myCount];
int i;
for (i = 0; i < myCount; i += 1)
{
TextBox textBox = new TextBox();
textBox.ID = "myTextBox" + i.ToString();
MyPlaceHolder.Controls.Add(textBox);
dynamicTextBoxes[i] = textBox;
LiteralControl literalBreak = new LiteralControl("

");
MyPlaceHolder.Controls.Add(literalBreak);
}
}

protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnAddTextBox_Click(object sender, EventArgs e)
{

}
protected void MyButton_Click(object sender, EventArgs e)
{
MyLabel.Text = "";
foreach (TextBox tb in dynamicTextBoxes)
{
MyLabel.Text += tb.Text + " :: ";
}
}
public static Control GetPostBackControl(Page thePage)
{
Control myControl = null;
string ctrlName = thePage.Request.Params.Get("__EVENTTARGET");
if (((ctrlName != null) & (ctrlName != string.Empty)))
{
myControl = thePage.FindControl(ctrlName);
}
else
{
foreach (string Item in thePage.Request.Form)
{
Control c = thePage.FindControl(Item);
if (((c) is System.Web.UI.WebControls.Button))
{
myControl = c;
}
}

}
return myControl;
}
}


Also see my other blogs: TreeView using database
                                                                Get Primary key of gridview on edit commant

Monday, November 15, 2010

Reset table id's "O"

use

DECLARE @reset_id varchar(200)




DECLARE reset_cursor CURSOR FOR

select Table_schema+'.'+Table_Name as tname from information_schema.tables

where Table_Type='BASE TABLE'

OPEN reset_cursor;




FETCH NEXT FROM reset_cursor

INTO @reset_id;




WHILE @@FETCH_STATUS = 0

BEGIN




DBCC CHECKIDENT(@reset_id,RESEED,0)

print @reset_id;

FETCH NEXT FROM reset_cursor INTO @reset_id;

END;




CLOSE reset_cursor;

DEALLOCATE reset_cursor;






Also see my other blogs: TreeView using database
                                                                Get Primary key of gridview on edit commant
use

DECLARE @reset_id varchar(200)




DECLARE reset_cursor CURSOR FOR

select Table_schema+'.'+Table_Name as tname from information_schema.tables

where Table_Type='BASE TABLE'

OPEN reset_cursor;




FETCH NEXT FROM reset_cursor

INTO @reset_id;




WHILE @@FETCH_STATUS = 0

BEGIN




DBCC CHECKIDENT(@reset_id,RESEED,0)

print @reset_id;

FETCH NEXT FROM reset_cursor INTO @reset_id;

END;




CLOSE reset_cursor;

DEALLOCATE reset_cursor;

Upload Image File in defined Folder

if (ImageFileUpload.HasFile)
{
try
{
if (ImageFileUpload.PostedFile.ContentType == "image/jpeg")
{
if (ImageFileUpload.PostedFile.ContentLength <>
{
string filename = Path.GetFileName(ImageFileUpload.FileName);
ImageFileUpload.SaveAs(Server.MapPath("~//Images/")+ filename);
UploadErrorlbl.Text = "File Uploaded";
LblFilePath.Text = ImageFileUpload.PostedFile.FileName;
}
else
UploadErrorlbl.Text = "Upload status: Only JPEG files are accepted!";

}
}
catch (Exception ex)
{
UploadErrorlbl.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;

}
}


Also see my other blogs: TreeView using database
                                                                Get Primary key of gridview on edit commant