|
hi,
well u can use it like this
on form's load event ...
if you are using C#.net
if (!IsPostBack)
{
GridView1.EditIndex = 0;//assuming that you want to show first row editable
GridView1.DataSource = "Your DataSource";
GridView1.DataBind();
}
Faraz Shah Khan
MCP, MCAD.Net
Blog
|
|
|
|
|
If I use your code, I get an error message, can you tell me why?
Here is my code:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.EditIndex = 0;
GridView1.DataSource = "SqlDataSource1";
GridView1.DataBind();
}
}
}
Here is the error message:
System.InvalidOperationException was unhandled by user code
Message="for GridView1 are DataSource and DataSourceID defined. Delete one of them (is translated by me German = English)”
Source="System.Web"
StackTrace:
bei System.Web.UI.WebControls.DataBoundControl.ConnectToDataSourceView()
bei System.Web.UI.WebControls.DataBoundControl.GetData()
bei System.Web.UI.WebControls.DataBoundControl.PerformSelect()
bei System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
bei System.Web.UI.WebControls.GridView.DataBind()
bei _Default.Page_Load(Object sender, EventArgs e) in
....
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
bei System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
bei System.Web.UI.Control.OnLoad(EventArgs e)
bei System.Web.UI.Control.LoadRecursive()
bei System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
Thanks!
Best regards
Klaus
|
|
|
|
|
Hi,
As you have already defined DataSourceID and DataSource try your code like this
GridView1.EditIndex = 0;
GridView1.DataBind();
The error is generated probably because when you have already assinged DataSource and DataSourceID in designer and try to assign DataSource again in code it gives error.
Faraz Shah Khan
MCP, MCAD.Net
Blog
|
|
|
|
|
Datagrid with checkbox using asp.net.so i will select checkbox and the show to datagird datas show in lable,datagrid using paging concept,I need select checkbox in page 1 some datas and then select page 2 in some datas.but i can't any one only.Any body know,tell immediately...and thanks.........
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ldstdateset As New DataSet
Dim lobjdatatier As New TicDataTier
ldstdateset = lobjdatatier.ExecStoredProc("TIC_GET_tTic_MM_Modules", lstrparameter, "Gmdataset")
Me.MyDataGrid1.DataSource = ldstdateset.Tables(0)
Me.MyDataGrid1.DataBind()
End Sub
Private Sub MyDataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles MyDataGrid1.PageIndexChanged
Me.MyDataGrid1.CurrentPageIndex = e.NewPageIndex
Me.MyDataGrid1.DataBind()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer = 0
Dim mySelection As StringBuilder = New StringBuilder
mySelection.Append("Selected Row(s):<hr><br>")
Dim GridItem As DataGridItem
For Each GridItem In MyDataGrid1.Items
Dim myCheckbox As CheckBox = CType(GridItem.Cells(0).Controls(1), CheckBox)
If myCheckbox.Checked = True Then
i = i + 1
mySelection.AppendFormat("{0}<br>", GridItem.Cells(1).Text)
' mySelection.Append("<hr>")
mySelection.AppendFormat("{0}<br>", GridItem.Cells(2).Text)
End If
Next
mySelection.Append("<br>")
mySelection.Append("<hr>")
mySelection.AppendFormat("Total selected Value is: {0}<br>", i.ToString())
Me.Label1.Text = mySelection.ToString.Trim()
End Sub
Private Sub MyDataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles MyDataGrid1.PageIndexChanged
Me.MyDataGrid1.CurrentPageIndex = e.NewPageIndex
Me.MyDataGrid1.DataBind()
End Sub
And once again thanks
regards,
sen.V
|
|
|
|
|
Hi,
what i believe you will be required to create a method that will check the selected rows of the grid view. when the page is changing call that method and store the selected row in a session. on the next page when user select rows repeat the same process. note that the method will not only be called no the page index change but also where there is some post back on the page.
hope it will help.
Faraz Shah Khan
MCP, MCAD.Net
Blog
|
|
|
|
|
My application's session lasts for only 2 or 3 minutes even if I set session timeout to 30 minutes in web.config file.
<system.web>
<sessionState timeout ="30" ></sessionState>
</system.web>
Can anyone tell the reason
|
|
|
|
|
It's hard to tell what is causing the problem. Are you doing anything that will reset the application, like modifying web.config runtime etc ? If yes it will clear all session variables.
|
|
|
|
|
Hi,
Check your session timeout in IIS as well. Follow the path
IIS -> Default Website -> YourWebSite -> (right click) Properties -> (from Tab) ASP.Net -> Edit Configuration -> (from Tab) State Management.
Check the session out time here and try to increase it if it is lesser than 30 mins.
Faraz Shah Khan
MCP, MCAD.Net
Blog
|
|
|
|
|
The Application is fine on the Dev machine, but on the production server it choked on files that have 1KB or more...
I have set the buffer size to 2048
|
|
|
|
|
see this link
http://www.codeproject.com/KB/custom-controls/PSGridView.aspx
I have an ERROR when I click on INSERT for add new row and after click on CANCEL.
I use the button ADD on gridview to inser a new row.
The control insert a new row, and this is an error!
can you welp me to correct this bug?
thanks
Giano
|
|
|
|
|
zio_pino wrote: see this link
Yes, I can see it.
Abandon hope all ye who answer here.
Pete O'Hanlon - the General Discussions forum
|
|
|
|
|
Has everyone see this problem?
|
|
|
|
|
hi, i'm posting because i have a problem i can't manage to solve...
i have a page with a row of DropDownLists, and what i want to do is this: when the user selects a value from one of the dropdowns , a new one is created under the selected, with the same values of the previous one, except for the selected one.
i know i have to write a function in c# called from OnSelectedIndexChange, but i can't understand how to create the new ddl from the code..
can anyone one help me or suggest a better way to do that?
i'm working on Visual web Developer using C#
thanks anyway, and sorry for the poor english..
bye
Kontax
|
|
|
|
|
If the second drop down has all the same value, minus the one selected you should be using a multi-select box instead of a select drop down. Then the user can select multiple choices w/o going back and forth between the server and w/o the complexity you're talking about.
If you're doing this to limit the number of choices the user makes, you could do this in javascript. Then on the server-side, validate the data a second time to make sure the user didn't try and bypass your client-side script.
|
|
|
|
|
Yes, the second one should have the same values except for the previously selected one. The problem is that after the first selection made with the DropDownList, the user can chose, for the selected value, properties from another DDL, and then another value for this one. So, when the user opens the page, he see a row of DDL. I need that, after the row he finish fulling it, another raw is created under the existing one, and so on, and only the mix of choises done before couldnt be re-done after...
That's the reason why I can't use a multi-select box..
I hope I explaned it well..
About javascript:i'm not used to it, do you really think I can do what I need better using javascript?
how could i do it?
Thanks anyway for the reply
|
|
|
|
|
Sounds like I didn't understand what it is you are trying to do. To clarify, it sounds like you are trying to allow the user to fill out a row of DDL. And then AFTER they have completed that row you want to give them a new row of DDL controls, minus the value(s) from the previous row.
If this is the case, then I recommend that when the user has completed the current row you will allow them to submit those changes to the server. You could use the SelectedIndexChanged of the last DDL of the row, or a command button.
When the user submits the selected values, create a new row in your data source and then rebind your Grid or list (whichever you are using) with the updated data source.
Here's an blog post on using the GridView's footer template to insert new rows: http://geekswithblogs.net/casualjim/articles/51360.aspx[^]. Just put all your DDLs into the footer row and proceed as I recommended above.
If your data source isn't meant to actually update a database or some other persisted store, but is just transient form data for some operation then instead of updating a persisted store you can maintain the data source in a session variable until the user has completed their operation. Then clear out the session variable when you are done.
|
|
|
|
|
Sir,
I m adding texbox in grid at runtime . it added successfully
but my problem is that how to read a value in a texbox i m sending
my code plz check this code give me reply
SqlDataAdaptor da=new SqlDataAdaptor("Select * from mytable",MyConnectionString);
DataSet dtSet=new DataSet();
da.Fill(dtSet);
GridView1.DataSource=dtSet.Table[0];
GridView1.DataBind();
TextBox txt ;
string strID;
//Add Textbox in a grid
for (int i = 0; i < dtSet.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < dtSet.Tables[0].Columns.Count; j++)
{
txt = new TextBox();
strID = i.ToString()+j.ToString();
txt.ID=strID;
GridView1.Rows[0].Cells[0].Controls.Add(txt);
}
}
//Read This TextBox Value
string strTextID;
for (int i = 0; i <GridView1.Rows.Count ; i++)
{
for(int j=0;j<GridView1.Columns.Count;j++)
{
strTextID=i.ToString()+j.ToString();
TextBox txt = (TextBox)GridView1.Rows[i].Cells[j].FindControl(strTextID);
string strText=Txt.Text;//This Statement Give me error
}
}
plz send me reply
Thanks & Regards
Lav Naphade
lav naphade
|
|
|
|
|
|
sir,
my problem is my gridview column size is not fix so i can not
add column in a template control so adding textbox in a grid at
run time .
how to add textbox in a ItemTemplate at runtime or template controlt?
plz sir give me proper solution .
lav naphade
|
|
|
|
|
To add the control you should be using the RowDataBound event (http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx[^]) like this:
<br />
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){<br />
if(e.Row.RowType == RowType.DataRow){<br />
txt = new TextBox();<br />
strID = "textBox1";<br />
txt.ID=strID; <br />
<br />
e.Row.Cells(1).Controls.Add(txt)<br />
}<br />
}<br />
Try recursively searching the result of : GridView1.Rows[i].Cells[j]. Instead of calling
GridView1.Rows[i].Cells[j].FindControl(strTextId). Do a recursive search of each of the child controls like this:
<br />
Control ctrl = GridView1.Rows[i].Cells[j];<br />
<br />
TextBox txt = FindControlRecursive(ctrl, strTextId) as TextBox;<br />
if(txt != null){<br />
}<br />
Where your recursive function looks like this:
<br />
private Control FindControlRecursive(Control current, String textId){<br />
Control result = current.FindControl(textId);<br />
if(result != null)<br />
return result;<br />
<br />
foreach(Control ctrl in current.Controls){<br />
result = FindControlRecursive(ctrl, textId)<br />
if(result != null)<br />
return result;<br />
}<br />
<br />
return null;<br />
}<br />
|
|
|
|
|
I nested a repeater inside a gridview templateField, this works fine, the problem is now the gridview width will not expand when the page is expanded.
Prior to this I had nested gridviews and the parent gridview's width expanded with the page. Is there a workaround to get the parent grid to expand with a nested repeater?
|
|
|
|
|
Hello everybody,
I read the excellent article about inserting a captcha control in a webpage, located here[^].
I liked so much the idea, that I wanted to extend the standard Login webcontrol which comes with ASP.NET 2.0, by adding a captcha image to be read and its content typed into a textbox.
The solution I found in the article uses the Page Session to generate an unique ID, that is then compared to what the user types.
My problem is that when I try to implement the very same solution in the webcontrol, I cannot access the Page object at all! It's like I cannot retrieve the page object my new webcontrol refers to, from within the control itself.
Is there some workaround to access the Page property?
If not, what could I use to generate an unique ID to be compared? I was thinking of simply generating a random number, but I do not know if it's recommendable.
Thanks in advance
Rey9999
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|
|
Rather than creating your own user control, couldn't use the login control template to include the captcha?
only two letters away from being an asset
|
|
|
|
|
I could.. but you know, this was not something I needed done for work, it was just to see if I were still able to extend existing cotrols. I liked the "login+captcha" idea, that's all. Anyway, I went with the random number approach, not so elegant but it works.
Now I have another problem:
How can I tell the control that it first has to check the correctness of the captcha?
I tried overriding the event OnLoggingIn, but this seems to happen when the login has already taken place.
Any ideas?
Thanks in advance
Rey9999
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|
|
The random number approach is a failure: since the page seems to reload the control after the loggingin procedure, I cannot have a unique identifier for each login attempt, beside the page session.
But how can I access it from the webcontrol itself?
Any help would be much appreciated. Thank you.
Rey9999
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|