Howdy All,
I am trying to get the data from a row of a data grid in asp.net This
is a data grid with five columns (two of the hidden) as follows:
<asp:datagrid id="grdMatching" runat="server" Width="100%"
Visible="False" Height="160px" AutoGenerateColumns="False"
AllowSorting="True" onselectedindexchanged="GetRow">
<Columns>
<asp:ButtonColumn Text="Select" ButtonType="PushButton"
CommandName="Select"></asp:ButtonColumn>
<asp:TemplateColumn>
<HeaderTemplate>
Name
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "FullName") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<HeaderTemplate>
Matches
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Matches") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "GivenName") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
I am trying to use the ItemCommand event to get the data from the cells
as shown in the MSDN help but everything it comes back blank. Can
somebody tell me what I a am doing wrong? Here is the code I am using
in the ItemCommand event:
private void grdMatching_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string sConnection = "user
id=user;password=password;database=dbname;server=s ervername;Connect
Timeout=30";
SqlConnection myConn = new SqlConnection(sConnection);
SqlCommand myCommand;
SqlDataAdapter myDA = new SqlDataAdapter();
DataSet myDS;
string sName = "";
string sGivenName = "";
string sSql = "";
TableCell objCell = e.Item.Cells[3];
sName = objCell.Text;
objCell = e.Item.Cells[4];
sGivenName = objCell.Text;
if (sName.Length > 0 || sGivenName.Length > 0)
{
sSql = "Select top 100 InstrNum, FileType, FileDate, Book, Page,
Series, Type, Description, Series, Name, GivenName, RTrim([Name]) +
ISNULL(',' + RTrim([GivenName]), '') As [FullName] From NCLand Where
[Name] = '" + sName + "' AND [GivenName] = '" + sGivenName + " Order by
[Name], [GivenName]";
myCommand = new SqlCommand(sSql, myConn);
myDA = new SqlDataAdapter();
myDA.SelectCommand = myCommand;
myConn.Open();
myDS = new DataSet();
myDA.Fill(myDS, "SearchResults");
grdItems.DataSource = myDS.Tables["SearchResults"].DefaultView;
grdItems.DataBind();
grdItems.Visible = true;
}
}
This event fires but both cells come back with empty strings. How can
I get the data out of the cells?
Thanks
dbl 4 8055
Try placing Labels into the hidden columns and bind the values to them. When
checking for values, locate controls using FindControl method
(e.Item.FindControl...) and get the Text value from Label's Text property.
--
Teemu Keiski
ASP.NET MVP, Finland
"DBLWizard" <ib*********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com... Howdy All,
I am trying to get the data from a row of a data grid in asp.net This is a data grid with five columns (two of the hidden) as follows: <asp:datagrid id="grdMatching" runat="server" Width="100%" Visible="False" Height="160px" AutoGenerateColumns="False" AllowSorting="True" onselectedindexchanged="GetRow"> <Columns> <asp:ButtonColumn Text="Select" ButtonType="PushButton" CommandName="Select"></asp:ButtonColumn> <asp:TemplateColumn> <HeaderTemplate> Name </HeaderTemplate> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "FullName") %> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn > <HeaderTemplate> Matches </HeaderTemplate> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "Matches") %> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn Visible="False"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "Name") %> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn Visible="False"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "GivenName") %> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:datagrid>
I am trying to use the ItemCommand event to get the data from the cells as shown in the MSDN help but everything it comes back blank. Can somebody tell me what I a am doing wrong? Here is the code I am using in the ItemCommand event:
private void grdMatching_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { string sConnection = "user id=user;password=password;database=dbname;server=s ervername;Connect Timeout=30"; SqlConnection myConn = new SqlConnection(sConnection); SqlCommand myCommand; SqlDataAdapter myDA = new SqlDataAdapter(); DataSet myDS; string sName = ""; string sGivenName = ""; string sSql = "";
TableCell objCell = e.Item.Cells[3]; sName = objCell.Text; objCell = e.Item.Cells[4]; sGivenName = objCell.Text;
if (sName.Length > 0 || sGivenName.Length > 0) { sSql = "Select top 100 InstrNum, FileType, FileDate, Book, Page, Series, Type, Description, Series, Name, GivenName, RTrim([Name]) + ISNULL(',' + RTrim([GivenName]), '') As [FullName] From NCLand Where [Name] = '" + sName + "' AND [GivenName] = '" + sGivenName + " Order by [Name], [GivenName]"; myCommand = new SqlCommand(sSql, myConn); myDA = new SqlDataAdapter(); myDA.SelectCommand = myCommand; myConn.Open(); myDS = new DataSet(); myDA.Fill(myDS, "SearchResults"); grdItems.DataSource = myDS.Tables["SearchResults"].DefaultView; grdItems.DataBind(); grdItems.Visible = true; } } This event fires but both cells come back with empty strings. How can I get the data out of the cells?
Thanks
dbl
Columns with Visible=false are not rendered to client. That's why you are
getting back empty strings. You should hide columns with css style
display:none.
Eliyahu
"DBLWizard" <ib*********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com... Howdy All,
I am trying to get the data from a row of a data grid in asp.net This is a data grid with five columns (two of the hidden) as follows: <asp:datagrid id="grdMatching" runat="server" Width="100%" Visible="False" Height="160px" AutoGenerateColumns="False" AllowSorting="True" onselectedindexchanged="GetRow"> <Columns> <asp:ButtonColumn Text="Select" ButtonType="PushButton" CommandName="Select"></asp:ButtonColumn> <asp:TemplateColumn> <HeaderTemplate> Name </HeaderTemplate> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "FullName") %> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn > <HeaderTemplate> Matches </HeaderTemplate> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "Matches") %> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn Visible="False"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "Name") %> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn Visible="False"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "GivenName") %> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:datagrid>
I am trying to use the ItemCommand event to get the data from the cells as shown in the MSDN help but everything it comes back blank. Can somebody tell me what I a am doing wrong? Here is the code I am using in the ItemCommand event:
private void grdMatching_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { string sConnection = "user id=user;password=password;database=dbname;server=s ervername;Connect Timeout=30"; SqlConnection myConn = new SqlConnection(sConnection); SqlCommand myCommand; SqlDataAdapter myDA = new SqlDataAdapter(); DataSet myDS; string sName = ""; string sGivenName = ""; string sSql = "";
TableCell objCell = e.Item.Cells[3]; sName = objCell.Text; objCell = e.Item.Cells[4]; sGivenName = objCell.Text;
if (sName.Length > 0 || sGivenName.Length > 0) { sSql = "Select top 100 InstrNum, FileType, FileDate, Book, Page, Series, Type, Description, Series, Name, GivenName, RTrim([Name]) + ISNULL(',' + RTrim([GivenName]), '') As [FullName] From NCLand Where [Name] = '" + sName + "' AND [GivenName] = '" + sGivenName + " Order by [Name], [GivenName]"; myCommand = new SqlCommand(sSql, myConn); myDA = new SqlDataAdapter(); myDA.SelectCommand = myCommand; myConn.Open(); myDS = new DataSet(); myDA.Fill(myDS, "SearchResults"); grdItems.DataSource = myDS.Tables["SearchResults"].DefaultView; grdItems.DataBind(); grdItems.Visible = true; } } This event fires but both cells come back with empty strings. How can I get the data out of the cells?
Thanks
dbl
I saw that, have fixed it, and verified that the table cells are
actually there in the source but they code still returnes blanks. I
added code to check all the cells in the row and they all come back
blank!!!!
Any thoughts?
Thanks
dbl
As I am reading more of the documentation it says that for "bound"
columns the values are in the Cell.Text. But I am using Template
Columns ... but it doesn't say how to get to the data for template
columns!!!! Is there a better way to do this?
Thanks
dbl This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: pkp303 |
last post by:
I have a page with a submit button (<asp.button/>). When run this page in
production the button fires and submits the form, however, when I run the
page on my local machine, it won't submit!
Any...
|
by: esoroka |
last post by:
Hello,
Trying to run a script what start ASP button:
document.Form1.all.click();
It is work one time only. Next script ignore it. Where can be
problem???
A full script is as follows:
|
by: JCE |
last post by:
I need to programmatically invoke an asp:Button click event from a
javascript function. The page containing the script and the button is the
HTML page associated with a WebUserControl-derived...
|
by: z. f. |
last post by:
Hi,
I'm having an aspx page with a server form.
i have a grid with a delete button and below the grid, another area with
inputs for inserting new values and an "add" button for submiting the...
|
by: hb |
last post by:
Hi,
When I add an asp:button (ex: id=btnLog) on home.aspx,
I need to create btnLog_Click() event in home.aspx.cs,
and also link this event and the button in OnInit() method
by adding:...
| |
by: Lam |
last post by:
I want to dynamic generate a asp:button in C# class, not in the HTML code
so that it can call the methods in the c# class,
I try to use "Response.Write("<asp:button...>")
it didn't show the button...
|
by: JV |
last post by:
This is for anyone who has tackled the accessibility issue on their web site
(and if you haven't, I bet you will in future).
Apparently the asp:button control always renders as '<input...
|
by: R.A.M. |
last post by:
Hello,
I have very simple problem which I present here second time, because I
haven't got a solution.
I need to process asp:Button click at server. I have written (my
experience is little) in...
|
by: chathura86 |
last post by:
I have a datagrid and I used a template column with an asp:button on it and I want to respond to a button click and find which row was selected. How would I do this?
<asp:TemplateColumn...
|
by: mazdotnet |
last post by:
Hi all,
I'm really stuck trying to figure the following out. I have been
working on a shopping portal where you can select products from a list
inside a repeater on the bottom of the page and...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |