Thursday, July 15, 2010

Taking index of a row in Gridview using RowCommand

For taking data using rowcommand property....

When you create the code of Gridview place the code like this for your customized Controls(Button)


<asp:imagebutton id="imgProfile" width="100px" height="100px" runat="server" imageurl="'<%#">' CommandName="cmdImage" CommandArgument='<%# Container.DataItemIndex %>' />
Here look at the COmmand argument property it should be like this. Then only we can take the Index of the Gridview.

Now, in Code behind you can call it like this....

string name = ((TextBox)GridView1.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("TextBoxName")).Text;

thus you can work on it getting the index of the row.

Fetch data from Footer of Gridview

Taking data from the Footer of a Gridview control in asp.net

GridViewRow row = GridView1.FooterRow;
if (e.CommandName == "cmdSUBMIT")
{
string name = ((TextBox)row.FindControl("TextBoxName")).Text;
Response.Write(name);
}

Tuesday, July 28, 2009

Dock panel in WPF and Databinding

<DockPanel >
<TextBox DockPanel.Dock="Top" Text="TOP"/>
<TextBox DockPanel.Dock="Right" Text="Right"></TextBox>
&l;tTextBox DockPanel.Dock="Bottom" Text="{Binding Path=Name}"/>
</DockPanel>


-----------------------------------
class person
{
string name = "Admin";
public string Name
{
get { return name; }
set { name = value; }
}
}
--------------------------------------
public Window1()
{
InitializeComponent();
person p = new person();
this.DataContext = p;
}
--------------------------------------

Friday, July 3, 2009

How to get Control ID's from websites using C# web browser

ButtonGetID_Click
---------------
MessageBox.Show(webBrowser1.Document.ActiveElement.Id.ToString());
----------------


Insert data to the Fileds
--------------------------

webBrowser1.Document.ActiveElement.InnerText = "smilu";
webBrowser1.Document.GetElementById("Passwd").InnerText = "password";

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

Click in HTML Buttons
-----------------------------
HtmlElement el = webBrowser1.Document.All["signIn"];
object obj = el.DomElement;
System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click");
mi.Invoke(obj, new object[0]);
------------------------------

Saturday, February 21, 2009

String Encryption

using System.Security.Cryptography;
using System.IO;

static string EncrypData;
static byte[] bytes =System.Text.ASCIIEncoding.ASCII.GetBytes("AbCdEfGh");
private void buttonEncrypt_Click(object sender, EventArgs e)
{
try
{
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);

StreamWriter writer = new StreamWriter(cryptoStream);
writer.Write(textBox1.Text);
writer.Flush();
cryptoStream.FlushFinalBlock();
writer.Flush();

EncrypData = Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
StreamWriter sw = new StreamWriter(@"C:\MyEncryption.DAT");
sw.Write(EncrypData);
sw.Flush();
sw.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void buttonDecrypt_Click(object sender, EventArgs e)
{
try
{
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(EncrypData));
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(bytes, bytes), CryptoStreamMode.Read);
StreamReader reader = new StreamReader(cryptoStream);

StreamWriter sw = new StreamWriter(@"C:\MyDecrypt.DAT");
sw.Write(reader.ReadToEnd());
sw.Flush();
sw.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

Friday, November 28, 2008

Globalization

using System.Globalization;
using System.Threading;

switch (comboBox1.SelectedIndex)
            {
                case 0:
                    {
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo("ar-SA");
                        Form1 frm = new Form1();
                        frm.ShowDialog();

                        break;
                    }
                case 1:
                    {
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
                        Form1 frm = new Form1();
                        frm.ShowDialog();
                        break;
                    }
                case 2:
                    {
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo("hi-IN");
                        Form1 frm = new Form1();
                        frm.ShowDialog();
                        break;
                    }
                default:
                    {
                        Form1 frm = new Form1();
                        frm.ShowDialog();
                        break;
                    }

Tuesday, November 4, 2008

Code Access Security

Code Access Security - Denying Read permission on C: drive


using System.Security.Permissions;
using System.IO;

[assembly:FileIOPermission(SecurityAction.RequestRefuse,Read="C:\\")]
namespace CASS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
StreamReader sr = new StreamReader("C:\\boot.ini");
MessageBox.Show(sr.ReadToEnd());
sr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}