Bharath Radhekrishna

Disabling some of the Textboxes in gridview edit

Posted by: onetidbit on: May 4, 2009

Situation: You need some text boxes disable when gridview is in edit mode.
=======

Solution:
======

1) Bind the Data without Sqldatasource Control
2) In Row Editing write the code:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
gridbind();
TextBox tx_chdets = (TextBox)GridView1.Rows[e.NewEditIndex].FindControl(”TextBox1″);
tx_chdets.Readonly=true;

}

Full gridvalues insert into database

Posted by: onetidbit on: April 9, 2009

In some situations we must insert a bunch of data into database table.

Just when we done some entry every entry must first go to gridview after all the entries completion we will push all the data by single click.

For this we need a run-time datatable:

Here is the code:

1) Decalare a Datatable globally.

DataTable dt1;

2) In the event you like place this code:

DataSet ds2 = new DataSet();

if (Session["dt1"] != null)
{

dt1 = Session["dt1"] as DataTable;
}
else
{
dt1 = new DataTable();

dt1.Columns.Add(”Name”);
dt1.Columns.Add(”Rollno”);

}
DataRow dr = dt1.NewRow();

dr["Name"] = TextBox1.Text;
dr["Rollno"] = TextBox2.Text;

dt1.Rows.Add(dr);

Session["dt1"] = dt1;
GridView1.DataSource = dt1;
GridView1.DataBind();

3) In the aspx page take a gridview
with boundfields as name and Rollno
4) For Inserting all the gridview values write foreach in button_click event.

foreach (GridViewRow gvr in GridView1.Rows)
{
string name1 = gvr.Cells[0].Text;
string roll = gvr.Cells[1].Text;

string str = “Data Source=RADHE;Initial Catalog=mnc_site;User ID=sa;Password=admin123″;
SqlConnection conn = new SqlConnection(str);

conn.Open();

string insqry = “insert into testing(Name,Rollno) values (@Name,@Rollno)”;

SqlCommand cmd = new SqlCommand(insqry, conn);

cmd.Parameters.Add(”@Name”, SqlDbType.VarChar).Value = name1 ;
cmd.Parameters.Add(”@Rollno”, SqlDbType.VarChar).Value = roll ;

cmd.ExecuteNonQuery();

conn.Close();
}

Any doubts mail me

Storing a image using asp.net

Posted by: onetidbit on: March 30, 2009

Hi, Use this code to store an image in the online server.

Before doing that we must give Permisiions to the folder in which you want to store Images.

Give Read and Write Permissions.

You must use fileupload control to do this:

Here is the code:

string extn =    System.IO.Path.GetExtension(FileUpload1.FileName);

if ((extn == “.jpg”) || (extn == “.gif”) || (extn == “.png”) || (extn == “.jpeg”))
{
path = Server.MapPath(”~/Documents”) + “//” + FileUpload1.FileName;
FileUpload1.SaveAs(path);

string script = “alert(’Document Uploaded Successfully…’);”;
Page.ClientScript.RegisterStartupScript(this.GetType(), “str”, script, true);

}
else
{
string script = “alert(’Invalid File Format…’);”;
Page.ClientScript.RegisterStartupScript(this.GetType(), “str”, script, true);
}
Any doubts Mail Me at radhek@gmail.com

Sometimes we will get the situation where we must insert NULL into datetime column in sql server.

Follow these steps to do that:

1) First Include the namespace:

using System.Data.SqlTypes;

2)  Declare

System.Data.SqlTypes.SqlDateTime getDate;
getDate = SqlDateTime.Null;

3) Insert using command Parameters

cmd11.Parameters.AddWithValue(”@encashed_date”, getDate);

——————————<>—————————————

Request Read Receipt for an Individual Message

Posted by: onetidbit on: February 25, 2009

Request a read receipt for an important message sent in Outlook Express

Topic : Outlook

When sending an important message in Outlook Express in Windows XP, you can request a read receipt for said message. This way you can help ensure your e-mail reached its destination and was read, even if it has not been responded to yet.

To request a receipt

1) When composing an e-mail message in OUTLOOK . Click “New Mail Message“.
2) In the new window opened click “options“  which is having a dropdown arrow.
3) In that again you click options.You will see a Modal Dialog box named “Message Options” there you select
Request a read receipt for this message“.

step-1

step-2


How to invoke a user defined event in the controls of Gridview

Posted by: onetidbit on: February 24, 2009

How to invoke a user defined event in the controls of Gridview
=============================

1) In aspx Take a gridview having one of the template fields i.e Item Template as LinkButton

<asp:TemplateField HeaderText=”Folio No”>
<EditItemTemplate>
<asp:TextBox ID=”TextBox1″ runat=”server” Text=’<%# Bind(”Folio_no”) %>’></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID=”Label2″ runat=”server” Text=’<%# Bind(”Folio_no”) %>’ OnClick=”click” ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>

2) In Code-behind Page:

protected void click(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
GridViewRow gvr = (GridViewRow)lb.Parent.Parent;

LinkButton lnk_fno = (LinkButton)gvr.FindControl(”Label2″);
}

How to Print a Gridview in ASP.NET 2.0

Posted by: onetidbit on: February 24, 2009

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"

<script language=”javascript” type=”text/javascript”>
function getconfirm()
{
return confirm(’Are you sure you want to change the Folio No?’);
}
function Button1_onclick() {
//open new window set the height and width =0,set windows position at bottom
var a = window.open (”,”, ‘ left = ‘ + screen.width + ‘,top=’ + screen.height + ‘,width=0,height=0,toolbar=0,scrollbars=0,status=0′);
//write gridview data into newly open window

//major change here get innerHTML Of the Div

a.document.write(document.getElementById(’innerData’).innerHTML);
a.document.close();
a.focus();
//call print
a.print();
a.close();
return false;
}

function IMG1_onclick() {
return Button1_onclick()
}

</script>

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"

Here the gridview must be placed in a DIV Tag
===================================

<div id=”innerHTML”>

Place Gridview Control here

</div>

<asp:ImageButton ID=”ImageButton1″ ImageUrl=”~/images/Printer-512×512.png” Width=30 Height=30 runat=”server” OnClientClick=”return Button1_onclick()” />

Tags:

Dropdownlist in gridview

Posted by: onetidbit on: February 21, 2009

Hi All,

The situation is Dropdownlist in Gridview.

While displaying the summary or reports we will use a Label for a particular column.
But in edit mode it must open in dropdownlist with selected Values as in the previous static mode.

I will explain clearly:

There is a table in database Months_TBL.
which contains 12 months.

1) First we must bind this with a datasource.
2) Attach this datasource to dropdown list.In the dropdownlist the query will be look like this
Select mid,month_name from Months_TBL.
3)Take a Template field for months which looks like this:

<asp:DropDownList CssClass=”textb” ID=”ddl1″ runat=”server” DataSourceID=”SqlDataSource1″ DataTextField=”month_name” DataValueField=”mid” AppendDataBoundItems=true selectedvalue=” >

<asp:Label ID=”Label1″ runat=”server” Text=”>

4) So While displaying if it shows February while we click edit the dropdown list will come as selected value as “February”.

Is it nice.

But carefully see that we have used “selectedvalue” property.

Presentation on Software as a Service on 12 Feb 09 By me.

Posted by: onetidbit on: February 12, 2009

dialog box with line break

Posted by: onetidbit on: January 30, 2009

string script = “alert(\”This dummy matter.\”+’\\n’+\” This dummy matter ‘This dummy matter’ \”+’\\n’+\” This dummy matter\”);”;
Page.ClientScript.RegisterStartupScript(this.GetType(), “script”, script, true);