Click here to Skip to main content
15,915,600 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Call a function declared in content page form master page Pin
moon_stick4-Dec-08 3:49
moon_stick4-Dec-08 3:49 
GeneralRe: Call a function declared in content page form master page Pin
Mohamed Arif4-Dec-08 4:03
Mohamed Arif4-Dec-08 4:03 
GeneralRe: Call a function declared in content page form master page Pin
moon_stick4-Dec-08 4:13
moon_stick4-Dec-08 4:13 
GeneralRe: Call a function declared in content page from master page [modified] Pin
Mohamed Arif4-Dec-08 5:42
Mohamed Arif4-Dec-08 5:42 
GeneralRe: Call a function declared in content page from master page [modified] Pin
moon_stick4-Dec-08 6:45
moon_stick4-Dec-08 6:45 
GeneralRe: Call a function declared in content page from master page Pin
Mohamed Arif4-Dec-08 7:12
Mohamed Arif4-Dec-08 7:12 
QuestionHow to save Iframe Content to server using Asp.net Pin
jamesrajesh4-Dec-08 2:42
jamesrajesh4-Dec-08 2:42 
QuestionError: GridView with checkbox --plz reply urgent Pin
premprakashbhati4-Dec-08 1:49
premprakashbhati4-Dec-08 1:49 
i have downloaded ur code of gridview with check boxes ...there u r not provided the functions....RetrieveItems()and DeleteRows() ...so i have written on my own ...i am getting 2 errors:

1.---->'gridview.RetrieveItems()': not all code paths return a value

2.----> No overload for method 'DeleteRows' takes '1' arguments
so plz go through the code and help me out its urgent....
thanks in advance.....

Here's the aspx.cs code:


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

public partial class gridview : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Include the JavaScript functions during Form_Load() itself.
CheckBoxJSFunctions();

if (!Page.IsPostBack)
{
PopulateGrid();
}
}
private static DataTable RetrieveItems() //Error No:1
{

//Create a connection to the SQL Server; modify the connection string for your environment
//SqlConnection MyConnection = new SqlConnection ("server=(local);database=pubs;Trusted_Connection=yes");
SqlConnection MyConnection = new SqlConnection("server=(local);database=pubs;UID=myUser;PWD=myPassword;");

// Create a Command object, and then set the connection.
// The following SQL statements check whether a GetAuthorsByLastName
// stored procedure already exists.
SqlCommand MyCommand = new SqlCommand("select * from sysobjects where id = object_id(N'GetPosts')" +
" and OBJECTPROPERTY(id, N'IsProcedure') = 1", MyConnection);

// Set the command type that you will run.
MyCommand.CommandType = CommandType.Text;

// Open the connection.
MyCommand.Connection.Open();

// Run the SQL statement, and then get the returned rows to the DataReader.
SqlDataReader MyDataReader = MyCommand.ExecuteReader();

// If any rows are returned, the stored procedure that you are trying
// to create already exists. Therefore, try to create the stored procedure
// only if it does not exist.
if(!MyDataReader.Read())
{
MyCommand.CommandText = "create procedure GetPosts" +
" (@date varchar(40),@title varchar(50),(@author varchar(40),@categories varchar(50),(@tags varchar(40),@comments varchar(50)(@status varchar(40), select * from Posts where" +
" Date like @date,PTittle like @title,Author like @author,Category like @categories,Tags like @tags,TotalComments like comments,PStatus like @status; select @RowCount=@@ROWCOUNT";
MyDataReader.Close();
MyCommand.ExecuteNonQuery();
}
else
{
MyDataReader.Close();
}

MyCommand.Dispose(); //Dispose of the Command object.
MyConnection.Close(); //Close the connection.
}






private void PopulateGrid()
{
// RetrieveItems() is a user defined function that calls the stored proc to retrieve data from the database.
DataTable dtItems = RetrieveItems();
GridView1.DataSource = dtItems;
GridView1.DataBind();
}

private void CheckBoxJSFunctions()
{
StringBuilder strScript = new StringBuilder();
strScript.Append("<script language=JavaScript>");
strScript.Append("function CheckAll(checkAllBox)");
strScript.Append("{");
strScript.Append("var frm = document.form1;");
strScript.Append("var ChkState = checkAllBox.checked;");
strScript.Append("for(i=0; i<frm.length; i++)");
strScript.Append("{");
strScript.Append("e=frm.elements[i];");
strScript.Append("if(e.type == 'checkbox' && e.name.indexOf('Id') != -1)");
strScript.Append("e.checked = ChkState ;");
strScript.Append("}");
strScript.Append("}");
strScript.Append("</script>");
if (!this.IsClientScriptBlockRegistered("clientScriptCheckAll"))
this.RegisterClientScriptBlock("clientScriptCheckAll", strScript.ToString());

//------------------------------------------------------------------------------

strScript.Append("<script language=JavaScript>");
strScript.Append("function CheckChanged()");
strScript.Append("{");
strScript.Append("var frm = document.form1;");
strScript.Append("var boolAllChecked;");
strScript.Append("boolAllChecked=true;");
strScript.Append("for(i=0; i<frm.length; i++)");
strScript.Append("{");
strScript.Append("e = frm.elements[i];");
strScript.Append("if (e.type =='checkbox' && e.name.indexOf('Id') != -1 )");
strScript.Append("if(e.checked == false)");
strScript.Append("{");
strScript.Append("boolAllChecked = false;");
strScript.Append("break;");
strScript.Append("}");
strScript.Append("}");
strScript.Append("for(i=0; i<frm.length; i++)");
strScript.Append("{");
strScript.Append("e=frm.elements[i];");
strScript.Append("if ( e.type =='checkbox' && e.name.indexOf('checkAll') != -1 )");
strScript.Append("{");
strScript.Append("if( boolAllChecked == false)");
strScript.Append("e.checked = false ;");
strScript.Append("else if(boolAllChecked == true)");
strScript.Append("e.checked = true;");
strScript.Append("break;");
strScript.Append("}");
strScript.Append("}");
strScript.Append("}");
strScript.Append("</script>");
if (!this.IsClientScriptBlockRegistered("clientScriptCheckChanged"))
this.RegisterClientScriptBlock("clientScriptCheckChanged", strScript.ToString());
}

// Function to get the selected checkbox values
private string GetSelected()
{
// Initially set the values to Blank
h_chkSelected.Value = "";

foreach (GridViewRow di in GridView1.Rows)
{
HtmlInputCheckBox chkBx = (HtmlInputCheckBox)di.FindControl("chkBoxId");

if (chkBx != null && chkBx.Checked)
{
Label lbl = (Label)di.FindControl("RowId");
h_chkSelected.Value = h_chkSelected.Value + lbl.Text + ",";
}
}

// If no checkbox selected, do not proceed further
string strDataToSend = "";
if (h_chkSelected.Value != "")
{
//Strip off the last comma before sending to stored proc
strDataToSend = h_chkSelected.Value;
strDataToSend = strDataToSend.Substring(0, strDataToSend.Length - 1);
}
return strDataToSend;
}

protected void btnDelete_Click(object sender, EventArgs e)
{
// This variable contains the selected rows in the format 1,2,3
string SelectedRows = GetSelected();
// User defined function that calls the stored proc to delete the selected items
DeleteRows(SelectedRows);
}

public virtual void DeleteRows()//error No:2
{
int rowIndex;
}

}
AnswerRe: Error: GridView with checkbox --plz reply urgent Pin
moon_stick4-Dec-08 4:24
moon_stick4-Dec-08 4:24 
AnswerRe: Error: GridView with checkbox --plz reply urgent Pin
Paul Conrad4-Dec-08 4:52
professionalPaul Conrad4-Dec-08 4:52 
Questionplz do replay i am facing problem since last working day Pin
sajjadlashari4-Dec-08 1:12
sajjadlashari4-Dec-08 1:12 
AnswerRe: plz do replay i am facing problem since last working day Pin
meeram3954-Dec-08 1:27
meeram3954-Dec-08 1:27 
AnswerRe: plz do replay i am facing problem since last working day Pin
AhsanS4-Dec-08 1:27
AhsanS4-Dec-08 1:27 
GeneralRe: plz do replay i am facing problem since last working day Pin
sajjadlashari4-Dec-08 17:56
sajjadlashari4-Dec-08 17:56 
GeneralRe: plz do replay i am facing problem since last working day Pin
Padmanabh Ganorkar4-Dec-08 18:59
Padmanabh Ganorkar4-Dec-08 18:59 
QuestionSuggesion Required related to filling country and city Dropdownlist [modified] Pin
mr_muskurahat4-Dec-08 0:07
mr_muskurahat4-Dec-08 0:07 
AnswerRe: Suggesion Required related to filling country and city Dropdownlist Pin
meeram3954-Dec-08 0:54
meeram3954-Dec-08 0:54 
AnswerRe: Suggesion Required related to filling country and city Dropdownlist Pin
AhsanS4-Dec-08 1:30
AhsanS4-Dec-08 1:30 
QuestionBizzare ViewState issue Pin
dmartu3-Dec-08 23:21
dmartu3-Dec-08 23:21 
AnswerRe: Bizzare ViewState issue Pin
Christian Graus4-Dec-08 8:44
protectorChristian Graus4-Dec-08 8:44 
GeneralRe: Bizzare ViewState issue Pin
dmartu4-Dec-08 22:56
dmartu4-Dec-08 22:56 
Questionrepeater control Pin
madan raj3-Dec-08 22:56
madan raj3-Dec-08 22:56 
AnswerRe: repeater control Pin
Abhijit Jana3-Dec-08 23:02
professionalAbhijit Jana3-Dec-08 23:02 
AnswerRe: repeater control Pin
nazeerahamad3-Dec-08 23:22
nazeerahamad3-Dec-08 23:22 
AnswerRe: repeater control Pin
J4amieC3-Dec-08 23:32
J4amieC3-Dec-08 23:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.