How to Add a GridView Column of Radio Buttons
In ASPX File add the following lines of code…
<form id=”form1″ runat=”server”>
<div>
<asp:Button ID=”btnLoad” runat=”server” Text=”Load Users” onclick=”btnLoad_Click” />
<asp:GridView ID=”gvUsers” runat=”server” OnRowCreated=”gvUsers_RowCreated”>
<Columns>
<asp:TemplateField HeaderText=”Method1″>
<ItemTemplate>
<asp:Literal id=”RadioButtonMarkup” runat=”server”></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Method2″>
<ItemTemplate>
<input name=”MyRadioButton” type=”radio” value=’<%# Eval(“Name”) %>’/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:Button ID=”bSubmit” runat=”server” Text=”Submit”
onclick=”bSubmit_Click” />
<br />
<asp:Label ID=”lmsg” runat=”server”></asp:Label>
</form>
In code behind file add the following code…
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLoad_Click(object sender, EventArgs e)
{
using (ProjectDBDataContext db = new ProjectDBDataContext())
{
var roles = from r in db.MUserInfos select r;
gvUsers.DataSource = roles;
gvUsers.DataBind();
}
}
private int UsersSelectedIndex
{
get
{
if (string.IsNullOrEmpty(Request.Form["UsersGroup"]))
return -1;
else
return Convert.ToInt32(Request.Form["UsersGroup"]);
}
}
protected void gvUsers_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Grab a reference to the Literal control
Literal output = (Literal)e.Row.FindControl(“RadioButtonMarkup”);
// Output the markup except for the “checked” attribute
output.Text = string.Format( “<input type=\”radio\” name=\”UsersGroup\” ” + “id=\”RowSelector{0}\” value=\”{0}\”", e.Row.RowIndex);
// See if we need to add the “checked” attribute
if (UsersSelectedIndex == e.Row.RowIndex)
output.Text += ” checked=\”checked\”";
// Add the closing tag
output.Text += ” />”;
}
}
protected void bSubmit_Click(object sender, EventArgs e)
{
int x = UsersSelectedIndex;
lmsg.Text = “method1: ” +x.ToString() + “</br>”;
string selectedValue = Request.Form["MyRadioButton"];
lmsg.Text += “method2: “ + selectedValue;
}
}
How to upload a file to ftp server with FileUpload control
private bool UploadToFTP(string ftpfilepath,HttpPostedFile fileToUpload)
{
try
{
string ftphost = “ftpaddress”;
string ftpfullpath = “ftp://” + ftphost + ftpfilepath;
Stream streamObj = fileToUpload.InputStream;
Byte[] buffer = new Byte[fileToUpload.ContentLength];
streamObj.Read(buffer, 0, buffer.Length);
streamObj.Close();
streamObj = null;
FtpWebRequest requestObj = FtpWebRequest.Create(ftpfullpath) as FtpWebRequest;
requestObj.Method = WebRequestMethods.Ftp.UploadFile;
requestObj.Credentials = new NetworkCredential(“username”, “password”);
Stream requestStream = requestObj.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Flush();
requestStream.Close();
requestObj = null;
return true;
}
catch
{
return false;
}
}
Profiler for Microsoft SQL Server 2005/2008 Express Edition
Download “AnjLab Sql Profiler”
http://code.google.com/p/sqlexpressprofiler/downloads/list and install it.
Use the following SQL statement to know your database ID
SELECT dbid FROM master.dbo.sysdatabases WHERE name = ‘Yourdatabasename’
New trace and use filters to trace particular database.

