|
I have a griview in my page with paging. The gridview contains the first column as UserId which is a Datakey column. The issue is when I go to secondpage, it is giving the error saying that " Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" .
On the second page, the index getting is 10. What am I doing wrong here? How should i get the datakey value? Following is the code I'm using.
int Userid = 0;
int index = 0;
foreach (GridViewRow gvr in SearchGrid.Rows)
{
CheckBox cb = (CheckBox)gvr.FindControl("chkbox1");
if (cb.Checked)
{
index = gvr.DataItemIndex;
Userid = Convert.ToInt32(SearchGrid.DataKeys[index].Value);
}
}
I am getting error on the last line when clicked on 2nd page. Can anybody provide any solution?
Thanks in advance.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
//if u r using only one datakey, then use like this
Userid = Convert.ToInt32(SearchGrid.DataKeys[index][0].Value);
Padmanabhan
|
|
|
|
|
I think this cannot be done. Because everytime I will ge the value at Index 0.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
DataKeys[index][0] in this index points ur row index and [0] points ur no.of datakeys u have...
if u give 2 datakeys named as sino and id
sino= Convert.ToInt32(SearchGrid.DataKeys[index][0].Value); //gives sino
id= Convert.ToInt32(SearchGrid.DataKeys[index][1].Value); //gives id
(or)
sino= Convert.ToInt32(SearchGrid.DataKeys[index]["sino"].Value); //sino
id= Convert.ToInt32(SearchGrid.DataKeys[index]["id"].Value); //gives id
Padmanabhan
|
|
|
|
|
oh.. Thank you very much. the information is pretty clear. thanks
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
You are looping through GridViewRows collection, therefore use GridViewRow.RowIndex property to get the index of the row in the for loop. Also change your code like this
index = gvr.RowIndex;
Userid = Convert.ToInt32(SearchGrid.DataKeys[index].Value);
|
|
|
|
|
Hello,
Visual Studio 2005
Default.ASPX
Two TextBoxes>>1.TextBox1 (To enter Start Roll Number)
2.TextBox2 (To enter End Roll Number)
Response.Redirect("Secm1998.aspx?startrol=" & TextBox1.Text & "&endrol=" & TextBox2.Text)
Secm1998.aspx>>1.CrystalReportSource1 2.CrystalReportViewer1
Secm1998.rpt
I wish to show only those records whose roll number (Oracle 10G Table) in the range of TextBox1 and TextBox2 in the CrystalReportViewer1.
For this:
How do i set CrystalReportViewer1.SelectionFormula as Rol (name of column in the table) in range of TextBox1 and TextBox2
Thanks & Regards
Girish Sharma
|
|
|
|
|
Set the formula like this
"{Student.Rol} >= " + rollNumber1 + " AND ({Student.Rol } <= " + rollNumber2
Here rollNumber1 and rollNumber2 are values of TextBox1 and TextBox2 respectively
|
|
|
|
|
Thanks for your reply and it worked fine; but one little question further:
Dim mySelectFormula As String = "ToNumber({secm98.rol}) >= " & Request.QueryString("startrol") & " AND ToNumber({secm98.rol}) <= " & Request.QueryString("endrol")
CrystalReportViewer1.SelectionFormula = mySelectFormula
Now it is asking username and password before showing the report; how do i set the username and password in the code.
Regards
Girish Sharma
|
|
|
|
|
In ASP.net how we show messagebox and alerts ti users when an error occurs????
|
|
|
|
|
Use javascript
OR
u Can use
Response.Write("alert('Enter the message here');") in the code window.
But when u use Ajax controls Response.Write not possible
u can use label and write the msg in that label
modified on Thursday, May 21, 2009 12:56 AM
|
|
|
|
|
use java script or show the messages in validation summary (in Vlaidation summary there is a property called ShowMessageBox="True")
Padmanabhan
|
|
|
|
|
Alternatively you can display a javascript alert after a postback by
Page.ClientScript.RegisterStartupScript(this.GetType(), "testkey", " window.alert('Your Alert Message')");
|
|
|
|
|
I use ASP.NET + C#
In My form I have a Gridview inside gridview i use a dropdown list
In dropdownlist it contain --Select-- and other items
I want to add a validation to this dropdownlist so that the user must choose an item other than --Select--
I need to validate using javascript .How can i do that
|
|
|
|
|
//if u have given selectedindex for your dropdownlist --select-- as 0
function error()
{
if ( document.getElementById('..._dropdownlist').selectedIndex = "0")
alert('select atleast one');
}
//but it will more easy if u provide a required field validator.
Padmanabhan
|
|
|
|
|
i will not work bcs i place the dropdownlist inside the gridview .
|
|
|
|
|
Add a javascript function through attributes.add in cs
for(int i=0;i< gridview.rows.count;i++)
{
DropDownList ddl = (DropDownList)gridview.rows[i].cells[cellid].findcontrol('id');
ddl.attributes.add("onchange","return func("+ddl.clientid+");");
}
Send the row id from the cs file
function func(ddl)
{
//Do the validation in javascript
}
Hope that helps!!
I was born dumb!!
Programming made me laugh !!!
--sid--
|
|
|
|
|
Please check yhe beolw script code
function check(id)
{
var n=document.getElementById("grd");
var namecontrol=id.name;
var myval=new Array();
var Arr=new Array();
myval=namecontrol.split("$")
var rowindex=myval[1];
var j=rowindex
if (document.getElementById("grd_"+j+"_ddl").value == '-- SELECT --')
{
alert("Please Select Sb Code..");
document.getElementById("grd_"+j+"_ddl").focus();
return false;
}
}
|
|
|
|
|
hi,
i have multi line text(ie..address)
for example,
insert into Db(address) values('" + txtaddress.text + "')
this address contain :-
Mr.Krish,
NH Road,
India.
its show error in comma operator.
so How to insert datas with comma operator ???
plz give solution for this..
Yours,
KaNNaN
-----------------------------------------------------------------
"Success is When Ur Signature Becomes An Autograph"
Mail To : foreverkans@gmail.com
|
|
|
|
|
user insert quary in stored procedure
or
use the insert command following like this
;
cmd.Parameters.AddWithValue("@RegFirstAddress", txtFirstAddress.Text);
cmd.CommandText = "insert into Tbl_Registration(RegFirstAddress) values (@RegFirstAddress)";
cmd.ExecuteNonQuery();
|
|
|
|
|
How can I use calender in asp.net?I know there is control named "calander" but that shows whole calender.What I want is that it show only a button on click a calander display.
|
|
|
|
|
you can use ajax calendar extender, it will be useful for u..
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1">
....
....
<asp:textbox id="txtDatetime" runat="server"> <asp:imagebutton id="ImageButton3" runat="server"
="" imageurl="~/Images/icon-calendar.gif" causesvalidation="False">
<cc1:calendarextender id="CalendarExtender1" runat="server" format="dd/MM/yyyy" targetcontrolid="txtDatetime" popupbuttonid="ImageButton3">
<cc1:maskededitextender id="MaskedEditExtender1" runat="server"
="" targetcontrolid="txtDatetime" mask="99/99/9999">
......
......
Padmanabhan
|
|
|
|
|
But it is not working.Infact after writing this code my design of page is disappearing.
|
|
|
|
|
I have a password mode textfield and a check box and a button.After giving password in textfield when checkbox is checked i.e. do true then button is enabled.But problem is,then password doesn't exist in textfield.How i can retrieve that password when button is clicked.
|
|
|
|
|
sorry its a default property for the password field......it will automatically clears the values when any event fires....
Padmanabhan
|
|
|
|