|
Hi there!
I am having difficulty in deleting a row from a gridview. I would like to delete a row of data in a gridview using checkbox but at the same time would not delete that data from the database. I have tried using deleteRow method but am still struggling. Is there a work-around solution for this?
BtnDelete Method
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
If Not IsPostBack Then
Dim Row2 As GridViewRow
Dim rowCell As String = ""
Dim count As Integer = 0
Dim test As Integer = 0
Try
For Each row As GridViewRow In GridView1.Rows
Dim checkBxText As String = CType(row.FindControl("chkDelete"), CheckBox).Text
Row2 = GridView1.Rows(count)
rowCell = Row2.Cells(2).Text
Dim cb As CheckBox = DirectCast(row.FindControl("chkDelete"), CheckBox)
If cb.Checked Then
Try
'GridView1.Row(row.RowIndex).Delete()
MsgBox(row.RowIndex)
GridView1.DeleteRow(row.RowIndex)
Catch ex As Exception
'MsgBox(count)
GridView1.DataBind()
End Try
Else
End If
count += 1
'DataBind()
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
'BindData(idSelection)
End Sub
Private Sub ToggleCheckState(ByVal checkState As Boolean)
For Each row As GridViewRow In GridView1.Rows
Dim cb As CheckBox = row.FindControl("chkDelete")
If cb IsNot Nothing Then
cb.Checked = checkState
End If
Next
End Sub
|
|
|
|
|
Have you tried deleting the row from the datatable you bounded the grid and don't save the datatable to the database back. just after delting the data from thedatatable rebind the grid.
|
|
|
|
|
I think you can simply use datatable for your table manipulation in disconnected environment.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
Thanks
Md. Marufuzzaman
|
|
|
|
|
Hi,
I have a generic list with the following collection
Name
Age
ID
Count
Mark
How can i remove the items with age=10
Thankyou
YPKI
|
|
|
|
|
|
How about
list.RemoveAll(f => f.Age == 10);
|
|
|
|
|
string connection2 = ConfigurationManager.AppSettings["conn"];
OleDbConnection con2 = new OleDbConnection(connection2);
string connectionString = ConfigurationManager.AppSettings["conn"];
if(DropDownList1.SelectedItem.ToString()=="ALL")
{
string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate ";
}
else
{
string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate and DOCTOR_NAME='"+DropDownList1.SelectedItem.ToString()+"'";
}
// wrap the connection and command in using block to avoid resource leaks.
using (OleDbConnection connection = new OleDbConnection(connectionString))
using (OleDbCommand command = new OleDbCommand(query, connection))
{
command.Parameters.AddWithValue("@StartDate", sel.ToShortDateString());
command.Parameters.AddWithValue("@EndDate", tmp.ToShortDateString());
connection.Open();
// using a reader. You don't need a dataset as you are not persisting it in memory
using (OleDbDataReader reader = command.ExecuteReader())
{
GridView1.DataSource = reader;
GridView1.DataBind();
}
connection.Close();
}
}
its showing an error like
Error 1 The name 'query' does not exist in the current context C:\Users\Ankit\Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx.cs 53 56 C:\...\WebSite1\
can anyone help
|
|
|
|
|
|
using (OleDbCommand command = new OleDbCommand(query, connection))
in dis line
|
|
|
|
|
Try This:
<big>string query ;</big>
if(DropDownList1.SelectedItem.ToString()=="ALL")
{
string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate ";
}
else
{
string query = "select * from appointment where DATE > @StartDate and DATE < @EndDate and DOCTOR_NAME='"+DropDownList1.SelectedItem.ToString()+"'";
}
|
|
|
|
|
|
I think it's because you are declaring the string variable, query, inside the If statement, therefore it is out of scope. Declare the variable at the top with the other declarations.
|
|
|
|
|
So how come you're smarty enough to use params for StartDate and EndDate but not for the doctor name?
|
|
|
|
|
Hi,
I have a gridview with autogenerated fields, 2 template fields, 1 command field. Now, I want to hide one of the columns in a gridview .
I have a code written in rowdatabound
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[2].Visible = false;
}
this code works well when I have not introduced allow paging=true.
but when I have a page indexing property my code for pageindexingchanging is:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gridview1.pageindex=e.newpageindex;
fillgrid();
}
where fillgrid is a function which is simply binding data coming from data base in gridview.
when I add page indexing to my gridview I get an error:
Specified argument was out of the range of valid values.
Parameter name: index
on this line:
e.Row.Cells[2].Visible = false;
any help shall be appreciated.
|
|
|
|
|
Instead of
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[2].Visible = false;
}
try
protected void GridView1_DataBound(object sender, EventArgs e)
{
e.Row.Cells[2].Visible = false;
}
|
|
|
|
|
Hi Meetu,
Meetu Choudhary wrote: protected void GridView1_DataBound(object sender, EventArgs e)
{
e.Row.Cells[2].Visible = false;
}
I tried but there is an error that it cannot access 'row' in the gridview1_databound event
|
|
|
|
|
Oh Sorry I posted Wrong Code.
Try This
protected void GridView1_DataBound(object sender, EventArgs e)<br />
{<br />
GridView1.Columns[0].Visible = false;<br />
}
|
|
|
|
|
Thanks for the code; it worked.
how can I add to your reputation from where?
|
|
|
|
|
Your Most Welcome. You can mark the answer as good answer or rate it..
|
|
|
|
|
|
Hi,
shouldn't the tags be named <fieldname> and <fieldvalue>? The server is throwing an error because you didn't set the arrays correctly.
Regards
Sebastian
|
|
|
|
|
Hi Sebastian,
i have set all the array Correctly like
object[] _fieldNames = new object[11];
object[] _fieldValues = new object[11];
_fieldNames[0] = "Set";
_fieldValues[0] = 1;
Output = call.Ex("A", _fieldNames, _fieldValues);
Can u tell me where i am wrong
thanks
prabhakar dwivedi
|
|
|
|
|
Well it seems that the client "call" you are using doesn't generate the correct soap-request. Look at the wsdl of the webservice and compare if the soap-request matches the wsdl. If not, the problem is the "call" object. How did you created it?
|
|
|
|
|
Hi,
I want to search a database for some documents and then present the search results from my web application.
I thought about using a GridView but that will display strictly in columns/rows. What I want is to display several rows for each result like this:
----------------------------------------------
Search Result #1
This is a bit of text describing the document
This is the actual URL of the document
Search Result #2
This is a bit of text describing the document
This is the actual URL of the document
etc.
-----------------------------------------------
Can anyone suggest a good approach? I can't use GridView for this and TextArea won't work either will it? Any other ideas?
|
|
|
|
|
Maybe a Repeater control?
|
|
|
|