|
Hi,
I'm populating a datagrid in ASP.NET 1.1 and after binding it to a collection, the ItemDataBound event allows me to access the data after it's entered as a row into the grid. I can add tooltips to the individual cells depending on the cell value and so on, which is very useful. However, I also have need to exclude some of my items from ever being displayed in the grid and so I'd like to handle an event which occurs before each row in the datagrid is populated. In this way I can filter the contents of my datagrid rather than apply any filtering to the collection class which for one reason or another, I don't wish to do.
Is there any way of capturing the item *before* it's added to the grid to stop it ever being displayed? In other words, can I filter a grid at this level?
Evil cannot be conquered in the world... It can only be resisted within oneself.
|
|
|
|
|
Hi there,
In this case, you can think of hiding the datagrid row (DataGridItem) using the Visible property, so depending on the databound bound to the row you can set either the specific cells of the row or the entire row invisible, and the user does not see that displayed on the grid.
|
|
|
|
|
Sir,
I want to confirm before deleting the row in the datagrid.By givig the message Are u sure u want to delete the record.
For that I am using the following code.
Select Case e.Item.ItemType
Case ListItemType.AlternatingItem, ListItemType.EditItem, ListItemType.Item
Dim b As Button
b = e.Item.FindControl("b")
b.Attributes.Add("onclick", "return confirm('Are you sure you want to delete ?');")
End Select
Now the problem My code for deleting the record is written in ItemCommand function of datagrid but control is not going after i press the ok botton of the messagebox.
Please help.
Thank You.
|
|
|
|
|
In ItemDataBound event add code below:
If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then <br />
Dim obj As Object = e.Item.Cells(4).Controls(0) <br />
Dim item As String = "this item" <br />
<br />
obj.Attributes("onclick") = String.Format("javascript:return confirm('Are you sure you want to delete {0}?')", item) <br />
<br />
End If
For more detail visit:
http://www.programmingknowledge.com/simpleDataGrid.aspx[^]
|
|
|
|
|
I have a Repeater which is bound to an ObjectDataSource. Its item template contains a Gridview and ObjectDataSource, displaying details for each item in the repeater. The Repeater's ObjectDataSource has three parameters, a date range and name. I set the default value of name to '%'. Everything displays fine, but when you try to edit a row in on of the grids, the page posts back, but the row is not in edit mode... I tried setting the parameters programmatically, which got my edit working, but when the name field was empty and I passed '%' in, I get unexpected results (different than what my table adapter returns with the same parameters when I preview the data through the designer). Anyone have some insight on this?
-- modified at 12:16 Wednesday 6th September, 2006
Just noticed something, if I use control parameters and enter the value '%' in the name text box, then the edit works correctly... But '%' is the default value for that parameter, so how is that any different?
-- modified at 14:19 Wednesday 6th September, 2006
I just discovered the reason the edit workes when the name textbox has a value. It causes the execution of the select method on my repeater's ObjectdataSource. Any ideas why that would affect the editing?
|
|
|
|
|
I guess that your sample code to build the gridview control relies on something such as the data binding expression ... that requires the Repeater's ObjectDataSource to execute its Select command. Below is a working sample with the two tables Categories and Products of the Northwind:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1">
<ItemTemplate>
<%# Eval("CategoryName") %>
<br />
<asp:Label runat="server" ID="lblCategoryID" Visible="false" Text='<%# Eval("CategoryID") %>'></asp:Label>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource2">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetProducts"
TypeName="Samples.AspNet.ObjectDataSource.NorthwindData">
<SelectParameters>
<asp:ControlParameter ControlID="lblCategoryID" Name="categoryID" PropertyName="Text" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</ItemTemplate>
</asp:Repeater>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OnSelecting="ObjectDataSource1_Selecting"
SelectMethod="GetCategories" TypeName="Samples.AspNet.ObjectDataSource.NorthwindData">
<SelectParameters>
<asp:Parameter DefaultValue="%" Name="name" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource2">
<Columns>
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetCategories"
TypeName="Samples.AspNet.ObjectDataSource.NorthwindData">
<SelectParameters>
<asp:Parameter DefaultValue="%" Name="name" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
You might want to post your code snippets if you still cannot figure it out.
|
|
|
|
|
Thanks for the reply, though I don't see what is different about the what I am doing and my edit does not work...
<asp:repeater id="repCommunities" runat="server" datasourceid="odsCommunity" enableviewstate="false">
<ItemTemplate>
<asp:HiddenField ID="txtID" runat="server" Value='<%# Eval("community_id") %>' />
<asp:GridView ID="gvCommunity" runat="server" AutoGenerateColumns="False" DataKeyNames="delay_id" DataSourceID="odsDelay">
<Columns>
<asp:BoundField DataField="delay_id" HeaderText="delay_id" InsertVisible="False" ReadOnly="True" SortExpression="delay_id" />
<asp:BoundField DataField="delay_day" HeaderText="delay_day" SortExpression="delay_day" />
<asp:BoundField DataField="delay_creator" HeaderText="delay_creator" SortExpression="delay_creator" />
<asp:BoundField DataField="delay_date" HeaderText="delay_date" SortExpression="delay_date" />
<asp:BoundField DataField="community_id" HeaderText="community_id" SortExpression="community_id" />
<asp:BoundField DataField="delay_action" HeaderText="delay_action" SortExpression="delay_action" />
<asp:BoundField DataField="delay_lot" HeaderText="delay_lot" SortExpression="delay_lot" />
<asp:BoundField DataField="delay_reason" HeaderText="delay_reason" SortExpression="delay_reason" />
<asp:CommandField ShowEditButton="true" />
</Columns>
</asp:GridView>
<br />
<asp:ObjectDataSource ID="odsDelay" runat="server" OldValuesParameterFormatString="original_{0}" TypeName="daSQL" SelectMethod="GetDelaysByCommunityAndDateRange" UpdateMethod="UpdateDelayAction" DeleteMethod="DeleteCommunity" InsertMethod="InsertDelay">
<SelectParameters>
<asp:ControlParameter ControlID="txtID" PropertyName="Value" DefaultValue="1" Name="communityID" />
<asp:ControlParameter ControlID="txtFrom" PropertyName="Text" DefaultValue="" Name="from" />
<asp:ControlParameter ControlID="txtTo" PropertyName="Text" DefaultValue="" Name="to" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="delay_lot" Type="String" />
<asp:Parameter Name="delay_day" Type="Int32" />
<asp:Parameter Name="delay_reason" Type="String" />
<asp:Parameter Name="delay_action" Type="String" />
<asp:Parameter Name="original_delay_id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="lot" Type="String" />
<asp:Parameter Name="day" Type="Int32" />
<asp:Parameter Name="creator" Type="String" />
<asp:Parameter Name="reason" Type="String" />
<asp:Parameter Name="communityID" Type="Int32" />
</InsertParameters>
</asp:ObjectDataSource>
</ItemTemplate>
</asp:repeater>
<asp:objectdatasource id="odsCommunity" runat="server" oldvaluesparameterformatstring="original_{0}"
selectmethod="GetUpdatedCommunitiesByDateRange" typename="QuadrantTableAdapters.communityTableAdapter"
deletemethod="Delete" insertmethod="Insert" updatemethod="Update" enableviewstate="False">
<DeleteParameters>
<asp:Parameter Name="Original_community_id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="community_name" Type="String" />
<asp:Parameter Name="community_active" Type="Boolean" />
<asp:Parameter Name="Original_community_id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="community_name" Type="String" />
<asp:Parameter Name="community_active" Type="Boolean" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="txtFrom" Name="from" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="txtTo" Name="to" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="txtCommunity" Name="name" PropertyName="Text" Type="String" DefaultValue="%" />
</SelectParameters>
</asp:objectdatasource>
|
|
|
|
|
The only difference is that you disable the ViewState that causes data is bound to the control late after the postback event is processed, and as a result of that the the GridView control is changed to the Edit mode. If you set the EnabledViewState property to false, you need to make sure that the control is recreated on postback based on the bound data, and it should appear early before the postback event is processed.
|
|
|
|
|
Can anybody help me to bind data to Ultrawebgrid at runtime dynamically?
I dont want to create it at design time at all.
When I bind ultrawebgrid just like datagrid, it says, object reference not set to an instance of an object.
using Infragistics.WebUI.UltraWebGrid;
protected Infragistics.WebUI.UltraWebGrid.UltraWebGrid grid1 ;
grid1 = new Infragistics.WebUI.UltraWebGrid.UltraWebGrid();
grid1.DataSource = dataset;
grid1.DisplayLayout.AutoGenerateColumns = true;
grid1.DataBind();
Please help
rmr
|
|
|
|
|
ok that should work although i normally set the DataMember Property as well,
so, it must be taht your dataset is not instantiated?
can you post more complete code, including funcitons called from?
my best practice for this is to use the designer to bind to a dataset at design time, then change the reference in Pre_Render() like so:
this.dataset = new DataSet();
this.ultraGrid1.DataSource = this.dataset;
this.ultraGrid1.DataMemeber = "DataTable";
this.ultraGrid1.DataBind();
obviously "DataTable" is the name of the table the band is bound to in the grid.
regs,
g00fy
|
|
|
|
|
Hi, Here is the code . And when i debug, the dataset is getting populated.
The error 'Object reference not set to an instance of an object' pops up at
grid1.DisplayLayout.AutoGenerateColumns = true; line in the code.
Am now having the grid in design time..and am giving this also
<%@ Register TagPrefix="igtbl" Namespace="Infragistics.WebUI.UltraWebGrid" Assembly="Infragistics.WebUI.UltraWebgrid.v2">
Please help.
using Infragistics.WebUI.UltraWebGrid;
using System.Data.SqlClient;
namespace A
{
public class sample : System.Web.UI.Page
{
protected Infragistics.WebUI.UltraWebGrid.UltraWebGrid grid1 ;
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
LoadContent();
}
}
private void LoadContent()
{
string strConnectionString = "data source=abc" +
"Database=Sample;User Id=a;Password=a;";
SqlConnection cnn;
cnn = new SqlConnection(strConnectionString);
try
{
cnn.Open();
}
catch (Exception ex)
{
throw ex;
}
grid1 = new Infragistics.WebUI.UltraWebGrid.UltraWebGrid();
SqlDataAdapter da;
DataSet ds1;
string s = "select * from a";
ds1 = new DataSet();
da = new SqlDataAdapter (s,cnn);
da.Fill(ds1, "Grid");
grid1.DataSource = ds1;
grid1.DisplayLayout.AutoGenerateColumns = true;
grid1.DataBind();
}
private void grid1_InitializeLayout(object sender,LayoutEventArgs e)
{
grid1.Width = System.Web.UI.WebControls.Unit.Pixel(400);
grid1.Height = System.Web.UI.WebControls.Unit.Pixel(400);
grid1.Bands[0].AllowAdd = Infragistics.WebUI.UltraWebGrid.AllowAddNew.No;
grid1.Bands[0].AllowDelete = Infragistics.WebUI.UltraWebGrid.AllowDelete.No;
grid1.DisplayLayout.AllowSortingDefault = AllowSorting.OnClient;
grid1.DisplayLayout.AllowColSizingDefault = Infragistics.WebUI.UltraWebGrid.AllowSizing.Free;
grid1.DisplayLayout.RowSizingDefault = Infragistics.WebUI.UltraWebGrid.AllowSizing.Free;
grid1.DisplayLayout.RowHeightDefault = System.Web.UI.WebControls.Unit.Pixel(22);
grid1.DisplayLayout.HeaderStyleDefault.Height = System.Web.UI.WebControls.Unit.Pixel(20);
grid1.Columns.FromKey("reportTitle").HeaderText = "Report Title";
grid1.Columns.FromKey("reportTitle").Width = System.Web.UI.WebControls.Unit.Pixel(550);
grid1.Columns.FromKey("reportTitle").AllowUpdate = AllowUpdate.No;
grid1.Columns.FromKey("reportName").HeaderText = "Report Title";
grid1.Columns.FromKey("reportName").Width = System.Web.UI.WebControls.Unit.Pixel(550);
grid1.Columns.FromKey("reportName").AllowUpdate = AllowUpdate.No;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void InitializeGridComponent()
{
this.grid1.InitializeLayout += new Infragistics.WebUI.UltraWebGrid.InitializeLayoutEventHandler(this.grid1_InitializeLayout);
//this.grid1.UpdateCellBatch += new Infragistics.WebUI.UltraWebGrid.UpdateCellBatchEventHandler(this.grid1_UpdateCellBatch);
//this.gridDocLink.UpdateCellBatch += new Infragistics.WebUI.UltraWebGrid.UpdateCellBatchEventHandler(this.gridDocLink_UpdateCellBatch);
// this.gridDocLink.DeleteRowBatch += new Infragistics.WebUI.UltraWebGrid.DeleteRowBatchEventHandler(this.gridDocLink_DeleteRowBatch);
// this.gridDocLink.AddRowBatch += new Infragistics.WebUI.UltraWebGrid.AddRowBatchEventHandler(this.gridDocLink_AddRowBatch);
}
}
}
rmr
|
|
|
|
|
Can we design dynamic tabstrip control at runtime without creating tabstrip control at design time? Am trying to do it by adding
%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %> at asp.net design page (.aspx)
and
Microsoft.Web.UI.WebControls.TabStrip tabControl = new Microsoft.Web.UI.WebControls.TabStrip();
at code behind.
Microsoft.Web.UI.WebControls.Tab tab=new Microsoft.Web.UI.WebControls.Tab();
tab.Text= " ok" ;
tab.ID = "1" ;
tabControl.Items.Add(tab);
Am not getting anything on page. Can somebody help???
rmr
|
|
|
|
|
You need to add the control to the Page's Control collection
Page.Controls.Add(tabControl);
regs
g00fy
|
|
|
|
|
Thanks for the reply.
But am not still able to get the tabcontrol. Please help
Design :
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
Code :
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Microsoft.Web.UI.WebControls.TabStrip tabControl = new Microsoft.Web.UI.WebControls.TabStrip();
Microsoft.Web.UI.WebControls.Tab tab=new Microsoft.Web.UI.WebControls.Tab();
tab.Text= " ok" ;
tab.ID = "1" ;
tabControl.Items.Add(tab);
Page.Controls.Add(tabControl);
}
-- modified at 10:20 Wednesday 6th September, 2006
rmr
|
|
|
|
|
ok i don't have that assembly and have never used it but this code works
protected void Page_Load(object sender, EventArgs e)
{
Table table = new Table();
table.Rows.Add(new TableRow());
table.Rows[0].Cells.Add(new TableCell());
table.Rows[0].Cells[0].Controls.Add(new LiteralControl("cell 0"));
Page.Controls.Add(table);
}
and this code doesn't work
protected void Page_Load(object sender, EventArgs e)
{
Table table = new Table();
table.Rows.Add(new TableRow());
table.Rows[0].Cells.Add(new TableCell());
table.Rows[0].Cells[0].Controls.Add(new LiteralControl("cell 0"));
}
hope that helps
g00fy
|
|
|
|
|
Hi Guys;
Here is the problem.
Im trying to Authenticate a user to my site but the function
User.Identity.IsAuthenticated always returns false
what could be the problem.
I also checked the web.config file with another project of mine which works fine there were no differences!!
Thanks in advance
Riazi
|
|
|
|
|
do you have authentication and roles and proviers set up in web.config?
do you have permission set up in web.config?
can you post your web.config?
regards,
g00fy
|
|
|
|
|
User.Identity works when you have passport credentials
a easy solution is to make a manual authentication of the user ID y password against to database, in true case you must to let pass the user, use the sentence e.Authenticated = true;
My project made that basic authentication, here the example
Logeo is the control's Login name
protected void Logeo_Authenticate(object sender, AuthenticateEventArgs e)
{
if ((Logeo.UserName == "a") && (Logeo.Password == "b"))
{
Mensaje.Text = "Welcome aboard";
e.Authenticated = true;
}
}
Keep Learning...
ff
|
|
|
|
|
britneyssssers wrote: User.Identity works when you have passport credentials
It is not only for Passport. Windows authentication also uses this. In fact I've never built a site that uses Passport authentication. Has anyone else? (I'm curous)
britneyssssers wrote: a easy solution is to make a manual authentication of the user ID y password against to database
An easy solution would be to use the built in functionality provided by the asp.net framework and add entries in the web.config to authenticate against. This is much easier than creating a database, tables and proceduces and the necessary overhead to use it.
only two letters away from being an asset
|
|
|
|
|
Hi all,
Any body know GOF Design patterns
Softy Boy
|
|
|
|
|
softy_boy wrote: Any body know GOF Design patterns
Yes.
|
|
|
|
|
lol colin,
yep me too.
g00fy
|
|
|
|
|
Yep, and a few others, like the Rube Goldberg pattern used by the last client.
only two letters away from being an asset
|
|
|
|
|
pls tell me on my mail id
g_parwez@rediffmail.com
g_parwez@yahoo.com
Softy Boy
|
|
|
|
|
Hi Friends,
I m using 1 session variable like this
Session["fullname"]="ABC";
then I pass this value to a class let say in which the FullName Property is declared with Public static key words
SessionInfo.FullName=Session[""].ToString();
It works fine for one user
but when i run two sessions what happens is
if Mr. "A" is already logged on the web site and after Mr. "A", Mr."B" logs in.
the name of Mr."A" changes to Mr."B" and on both browswer windows now name is Mr."B".
Would you please help me , where i am wrong?
Please if you do not understand my problem, do ask me.
thansk
Naveed Kamboh
|
|
|
|