Forms Data Controls :: Get Cell Info From The GridViewRowEventArgs?
Oct 1, 2010[Code]....
how do i get cell info from the GridViewRowEventArgs
[Code]....
how do i get cell info from the GridViewRowEventArgs
I generate dynamic grids based on a count value returned from some DB tables. the code for it goes like this : I give and Id to each grid that is generated.
if (myDataList1.Count >= 1)
{
for (int i = 0; i < myDataList1.Count; i++)
{
//retrieving the exact i count from pageload
ViewState.Add("newCount", i);
//creating the dynamic grid with its corresponding gridview properties.
grvDynamic = new GridView();
grvDynamic.ID = "GridView" + (i+3);
grvDynamic.AutoGenerateColumns = false;
grvDynamic.RowCreated += GridViewRowCreated;
grvDynamic.RowDataBound += grvDynamic_RowDataBound;
//adding bound field columns to retrieve data from stored proc
BoundField metric = new BoundField();
metric.HeaderText = "Goal ";
metric.DataField = "metric";
grvDynamic.Columns.Add(metric);
BoundField mtd = new BoundField();
mtd.HeaderText = "MTD";
mtd.DataField = "value_MTD";
grvDynamic.Columns.Add(mtd);
BoundField goal = new BoundField();
goal.HeaderText = "Tier Level Achieved";
goal.DataField = "value_goal";
goal.HeaderStyle.Width = Unit.Percentage(10);
grvDynamic.Columns.Add(goal);
BoundField you1 = new BoundField();
you1.HeaderText = "Month End";
you1.DataField = "firstLevel_you";
grvDynamic.Columns.Add(you1);
BoundField you2 = new BoundField();
you2.HeaderText = "Month End";
you2.DataField = "secondLevel_you";
grvDynamic.Columns.Add(you2);
ButtonField singleClick = new ButtonField();
singleClick.CommandName = "clickHyperlink";
singleClick.Visible = false;
grvDynamic.Columns.Add(singleClick);
BoundField metricId = new BoundField();
metricId.HeaderText = "Metric Id";
metricId.DataField = "metricID";
metricId.Visible = true;
grvDynamic.Columns.Add(metricId);
//binding the gridview to data.
grvDynamic.DataSource = data;
grvDynamic.DataBind();
grvDynamic.Columns[5].Visible = false;
}
}
protected void grvDynamic_RowDataBound(object sender, GridViewRowEventArgs e)
{
//this basically gets the metric Id's of rows with the ishyperlink flag set to 'Y'. I need to make these particular cells clickable var isClickable = (from md in myDataList3 where md.IsHyperLinkFlag == 'Y' &&
md.value_MTD != null select md.metricID).ToList();
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Get reference to button field in the gridview.
LinkButton _singleClickButton = (LinkButton)e.Row.Cells[5].Controls[0];
if (isClickable.Contains(Convert.ToInt32(e.Row.Cells[6].Text)))
{
e.Row.Cells[1].Style["cursor"] = "hand";
e.Row.Cells[1].Style["color"] = "blue";
e.Row.Cells[1].Style["textdecoration"] = "Underline";
e.Row.Cells[1].Attributes.Add("onClick", "window.location ='../HeaderPages/page2.aspx' ");
}
}
}
This code works perfectly fine , depending on the ishyperlink flag in the database...specific cells in the grid are made clickable and then redirected to page2.aspx My Issue: I need to capture which specific cell in which specific grid the user has clicked. store some information in sessions based on the cell clicked and use that information in page2.aspx.
I have a problem, with a gridview. When I try to make a OnRowDataBound I get the error "Gridviewroweventargs is inaccessible due to its protection level" I cann't figure out why.My aspx code for the gridview:
[Code]....
Now I have comment out everything in the function grdWaitingApproval_RowDataBound:
[Code]....
When I remove the line in the aspx file
[Code]....
the project runs fine and I get a list of users with username date and so on. But I nead to use the RowDataBound to select a picture to each row.
I have a regular method I want to call. I need to use properties of the GridViewRowEventArgs Class within this method.
i.e.
[Code]....
Of course the above code is not valid because I don't think you can put GridViewRowEventArgs within the method like that. I don't want to put it within a event handler because that even handler is doing other things. I want to be able to call this seperatley.
I have a grid view populated with some data included bit fields and I made an export to excel function For each row i need to check the cell with the bit value to change the cell color, but the cell is always empty, even if is the field is set to False or True. foreach (GridViewRow row in gv.Rows)
View 2 RepliesI'm having a weird problem where the GridView cell that I'm programmatically updating turns grey, and throws a null error when attempting to save row. I have been searching all day and have not been able to find a solution. I'm guessing there is a problem with my code, so here it is:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
How to set Height and ItemSource(Business Object as DataSource for Cell) for every Cell in DataGrid/ Grid? Shown below is part of code I am currently using with Grid Control. What I am currently doing is that I am using ListBoxItem, set Item Height and ItemSource at ListBoxItem Level, Add ListBoxitem to ListBox and then Add ListBox to Grid, It leaves me with just one row and multiple columns in the Grid, which is perhaps not the best way of doing it as it doesn't allow me to take benefits from UI Virtualization of Grid.
[code]....
I am open to use any control i.e. Grid/ DataGrid provided it allows me to set Cell Height and item source at Cell level. In my requirement, Cell height depends on the Item duration and size of image, which means the height of the cells may not be same across cells in any particular row.
I have a gridview on which there is a colume of image button for user to select a particular row. When a row is selected, a modal pop up appears for user to edit data and finally uers hit update button (within modal pop up). I expect to update the selected gridview row with info on modal pop up. My question is how do I get the row number within the Update_Click event.
View 2 RepliesI've been hunting for a solution to grab the radiobuttonlist when they answer that particular question. It varies for the number of questions, but only one displays at a time, but there could be a radiobuttolist or checkboxlist based on the question type. I was figuring I could do this easy in the row command of the gridview, but that hasn't worked out so well since I can't get the datarow for some reason.
View 1 RepliesI having a data from database which display in form of link button at a repeater control.Nw i want to get the particular data from the repeater contorl and redirect it to its respective page to show its details.May i know how to do it?
View 7 RepliesI have a gridview that has a dropdown on a template on the row. The user is wanting to change the value and update the record automatically. I know that when the value changes, I need to have the OnChange to trigger. I am not sure how to get the row so I can get the record ID so I can create a SQL statement to update this field.
Should I be using something other than the gridview?
I am using datareader to bind the datagrid, after the datagrind is bind. Is it possible to get the total row info.
MyDatagrid.DataSource = gDataReader
MyDatagrid.DataBind()
I have created a web based form which has a drop down list (DDL) that lists various company names. I want to create a box in the form which displays the contact info for that particular company which is chosen in the DDL. Also, I want this info to be in a greyed area so that user cant modify (can just copy it).
what asp tool i should use for this (I am guessing textbox wont be good enough since user can modify the info that populates in it)
I have two gridviews, where the first is databound to a sql table (but does not display the primary key info), and want to filter the data displayed on the second gridview by using the primary key info from the first gridview table, indicated by the selected row in the first gridview - how I could achieve this? its kind of like using the gridviews as a menu and sub menu display!
View 1 RepliesI have the following code reading in my xml file and sorting it by ID:
Dim ds As New DataSet
ds.ReadXml(Server.MapPath("/posts.xml"))
Dim dv As New DataView(ds.Tables(0))
dv.Sort = "id desc"
The only problem is that it isn't sorting it numerically (it's sorting it alphabetically 1, 10, 11, 2, 24, 3, 4...). It appears as though I have to convert that column into integers, but I haven't been able to figure out an efficient way to do that.
im ds As New DataSet
ds.ReadXml(Server.MapPath("/App_Data/posts.xml"))
'ds.Tables(0).Columns(0).DataType = TypeOf(Decimal)
Dim dv As New DataView(ds.Tables(0))
'dv.Sort = "date"
Using the code below, I am able to load my dynamic dropdownlist and supply it's selectedindex. But when I fire the update command I can see that the information displayed has been lost.
when I fire the update I don't lose data!
[Code]....
'm using a textbox to get the first 5 letters of the name.
An sqldatasource then finds the people who have names > than the five letters and picks up their ID numbers as well as their names.
After that I use a second sqldatasource to get one individual from that dropdownlist's persons name and id number and then using a detailsview I display that person.
Well both sqldatasouces work fine but it just does not pass the ID number when I debug it.
have an annoying problem. i'm trying to update single items in a databound listview. but when i click the update button it gives me the cannot insert NULL value. it doesnt seem to read anything from the textboxes which i have databound from the database. even though text is clearly shown...
i have setup my update statement and parameters, it uses the Update command name and ItemUpdating event. i catch the data from the textboxes by using e.ItemIndex and use the text assigned to the parameters in a SqlCommand.
The thing i'm aiming for too is that when an item is updated it stays on the page where the item was updated, (i was using response.redirect before but it went against my aim since the whole page reloaded)
I tried same method using C# and did not work for me. My case is very similar. Have my GridView Detail as thus
sp:GridView
ID="ResultGrid"
runat="server"
CellPadding="3"
BackColor="Black"
Font-Bold
="False"
Font-Italic="False"
Font-Overline="False"
Font-Underline="False"
ForeColor
="#333333"
pageSize="5"
UseAccessibleHeader="True"
AutoGenerateColumns="False"
DataKeyField
"S/N"
Font-Size="Small"
Font-Strikeout="False"
Caption="Contacts"
EmptyDataText
="No Record Added"
AutoGenerateDeleteButton="True"
OnRowCommand="DeleteRecord_Click"
>
<AlternatingRowStyle
BackColor="White"
/>
Within which I have my ImageButton Template as thus:
asp:TemplateField
HeaderText
="Delete">
<ItemTemplate
>
asp:ImageButton
ID="DeleteRecord"
OnClientClick
="return DeleteRow();"
I am developing a website in asp.net that user asp.net membership, users and profile tables.I am trying to display all the users that are registered in a grid along with their first name, last name, email and other profile information . unfortunately all this information is scattered in various tables in the database ( aspnet_users, profiles, membershipsetc)... Can you please tell me how to configfure the datasource & columns of my datagrid (control) to achieve what I am trying to do .. ?????
View 3 RepliesI am Working on a ASP.net project(VB.net), i have a gridview to display names of "Patients". Each patient has a unique "labID",
I have stored the patients "diagnosis" information in seperate tables( stool,urine, blood etc)
what I need is to retrieve this info when I click on a patients name in gridview.
I have a databound repeater and in this repeater is an imageButton. How do I pass info from the database into the click event? For example, I've got the description, heading and price fields populating labels, but want the id to go into the imagebuttons click event in order to build a querystring.
View 6 Repliesalmost typical master-detail scenario except the 'detail' data I want to display below the gridview will be coming from both the table that is bound to the gridview (master) and a related table.
simplified example: tableMain with field1, field2, field3 bound to master gridview. I need to select a row from the master gridview and have a form display below with field4 and field5 from tableMain, as well as all fields of tableDetail where field1 of tableMain equals field1 of tableDetail.
Is this what a 'formview' control is for? or do I just arrange my own controls to accommodate the data? Would a formview work considering my source will be partially from both the main table and the detail table? This is one of the scenarios were I know I could come up with something using none of the databound controls (except the master gridview), but I want to use the controls provided when it makes sense to do so, and utilize their benefits etc...
this item colum called Id.
rowItem.Cells[0].FindControl("Label1").ToString();
it insert my to the db this value:
System.Web.UI.WebControls.DataControlFieldCell
how can i get it value right? i mean to get the item,because in this cell i want to get the item of it.
I'm building an ASP.NET MVC 2 site where I'm currently implementing an OpenID sign-up form. Unfortunately, I'm foreseeing a possible security bug/vulnerability inside my architecture.
Here's how I want OpenID login to work:
User requests /Account/Login, Controller sends back OpenIDLogin View. User enters their OpenID into the View, then OpenID authorization takes place, and finally the OpenID is returned to the Controller.The Controller checks whether the OpenID is currently in use by a user in the system or not. If it is, the user is logged in to that account. If not, the registration process begins.
And now, the OpenID registration process:
The OpenID identifier, as well as any other information provided by the OpenID provider (such as email address or name), is put into my custom ViewModel and sent to my OpenIDRegistrationForm View.The RegistrationForm View stores the OpenID in a hidden field to make sure that it gets sent back to the Controller.The user fills in the RegistrationForm View and sends it back to the Controller.The Controller creates the user account and puts the OpenID into the database.
The bug that I see within my architecture is that a user could modify the hidden value in the RegistrationForm View. Thus, they could spoof their OpenID! I will make sure to add another round of checking to the final Registration Controller Action to make sure that the OpenID that is provided doesn't exist yet, but there is still a possibility for spoofing. Can my architecture be improved somehow? I don't want this to end badly...
One solution I'm considering is encrypting the OpenID before I send it to the View and then decrypting it when it reaches the Controller. Should I try this?