|
|
I have noticed that on my form the grid stop displaying after applying a style.
<cc1:GridView ID="gvSpecificationData" runat="server" PageSize="8"
Width="350px"
onselectedindexchanged="gvSpecificationData_SelectedIndexChanged"
BorderColor="#7F9DB9" BorderStyle="Solid" BorderWidth="1px">
<AlternatingRowStyle BackColor="#f8f6df" />
<RowStyle BorderColor="#7F9DB9" BorderStyle="Solid" BorderWidth="1px" />
<SelectedRowStyle BackColor="#f8f6df" />
</cc1:GridView>
This is the code behind
dt = Categories.GetCategories(1);
keys[0] = "Categoryid";
gvSpecificationData.DataSource = dt;
gvSpecificationData.DataKeyNames = keys;
gvSpecificationData.ShowHeader = false;
gvSpecificationData.DataBind();
Adding just a regular grid view control works
GridView1.DataSource = dt;
GridView1.DataKeyNames = keys;
GridView1.ShowHeader = false;
GridView1.DataBind();
i'm not sure what is going, has anybody experienced this with the control.
There are no error messages or anything, it just does not display anymore.
|
|
|
|
|
Hai guys,
this is vishnu vardhan,i have one problem
id name comment Selectfile
1 vishnu good Selectfile-----> this is link button
2 vardhan fine Selectfile-----> this is link button
so see the above data ,if i click the link buttton,then transfer the id into next page.
actually i tried in this way ,this code wrote in onclick link button event ,but i get how many row's are disply in grid that all row's r geting.but i need only selected rows.
so plez any on help to me
string IId="";
//for (int i = 0; i < grid.Rows.Count; i++)
//{
// GridViewRow row = grid.Rows[i];
// string isSelect = ((LinkButton)row.FindControl("lbSelectFile")).OnClientClick;
// if (isSelect)
// {
// IId =grid.Rows[i].Cells[0].Text;
// }
|
|
|
|
|
Hai guys,
this is vishnu vardhan,i have one problem
id name comment Selectfile
1 vishnu good Selectfile-----> this is link button
2 vardhan fine Selectfile-----> this is link button
so see the above data ,if i click the link buttton,then transfer the id into next page.
actually i tried in this way ,this code wrote in onclick link button event ,but i get how many row's are disply in grid that all row's r geting.
so plez any on help to me
string IId="";
//for (int i = 0; i < grid.Rows.Count; i++)
//{
// GridViewRow row = grid.Rows[i];
// string isSelect = ((LinkButton)row.FindControl("lbSelectFile")).OnClientClick;
// if (isSelect)
// {
// IId =grid.Rows[i].Cells[0].Text;
// }
|
|
|
|
|
hi.. i want to move next record using textbox in asp.net with c#....
plz send code for this....
Mohamed Ibrahim
|
|
|
|
|
Hi,
After clicking, is that possible to redirect to another web page? (such as an HyperLinkField & to recover the Id of the selected row with the Request.QueryString)
best regards
bruno
|
|
|
|
|
yes, it is...
there are of course multiple ways to make the same job, here is one.
you have to make the work in your itemtemplate...
by specifying the url of the page you want to open and eval the id value of your object for exemple
yourpage.apsx?objId=<%= eval("ObjectId") %>
and use the target property of the link to specify how it will be open... fix it to "_blank" if you want to open the uri in a new window...
Let's make code sharing our goal...
Blaise Braye
|
|
|
|
|
Thanks a lot for replying to me so quickly.
In fact I am actually using a RowDataBound on my Gridview:
-------------------
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';this.style.background='#FFF5E6'";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.background='none'";
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this, "Select$" + e.Row.RowIndex);
}
}
-------------------
Click on row works but of course nothing happens!
So I would like to code a GridView2_SelectedIndexChanged event but I don't know how to open another page (mypage.aspx?Id={0})
Is that possible to do it?
Best regards
Bruno
|
|
|
|
|
This looked like a great solution until I made one field into a template. Then the opening <itemtemplate> tag was undderlined in red with the message "(Validation) XHTML 1.0 Transitional: this name contains uppercase characters, which is not allowed."
I changed the tag to <itemtemplate>, and it worked, but I'm nervous about that error message. Do you have any idea what might have caused it?
Thanks,
-AndrewC
|
|
|
|
|
Hi, tnx for a great article.
I am trying to expand your Default2.aspx with two buttons(activate and deactivate), which should be visible depending upon wheter an attribute is true or not. For example, if your Class nations has an attribute, isActive:
Nation.isActive = true; we show the deactivate button
Nation.isActive = false; we show the activate button
My question is: how do i get the value for this attribute when i load the page, in page_Load() or when the detailsview is loaded, so i can set. button.visible = true or false
Tnx. Frodi, denmark
|
|
|
|
|
mmm ok, the idea is to use a TemplateField and to put in it a button.
So let's assume we have a new field in the Nation class:
private bool _IsActive = true;
/// <summary>
/// Is nation active
/// </summary>
public bool IsActive
{
get { return _IsActive; }
set { _IsActive = value; }
}
Then we add this field in the gridview:
<asp:TemplateField>
<itemtemplate>
<asp:Button runat="server" Text='<%# ((bool)Eval("IsActive"))?"deactivate":"activate" %>' />
</itemtemplate>
</asp:TemplateField>
So now it looks like
<dd:GridView runat="server" ID="gdv" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="Id" DataSourceID="objDtsNations" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="Id">
<itemstyle width="100px" />
<itemtemplate>
<a href="Default2.aspx?id=<%# Eval("Id") %>" title="See Details in an other window">Open</a>
</itemtemplate>
</asp:TemplateField>
<asp:BoundField DataField="Label" HeaderText="Label" SortExpression="Label" />
<asp:TemplateField>
<itemtemplate>
<asp:Button runat="server" Text='<%# ((bool)Eval("IsActive"))?"deactivate":"activate" %>' />
</itemtemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</dd:GridView>
I think this is the cleanest way you have to work with it. Now if you would like to get the id of the nation in the postbackurl... nothing more easy
<asp:Button runat="server" PostBackUrl='<%# "?toggle=" + Eval("Id") %>' Text='<%# ((bool)Eval("IsActive"))?"deactivate":"activate" %>' />
Then you are now able to check if the "toggle" attribute is in the query string and use it from you page_load method for instance.
Let's make code sharing our goal...
Blaise Braye
|
|
|
|
|
Hello again. tnx for the quick reply.
Actually i dont need the details from the detailsview. I only need to toggle the button between activate and deactivate. The Text for the button works fine, but i also need to call either an activate method or deactivate method, when clicking the button.
protected void Activate(object sender, EventArgs e)
{
//do something
}
protected void DeActivate(object sender, EventArgs e)
{
//do something else
}
How do i write the asp button onclick command? (dont know if this is possible to get it to choose between two methods!)
<asp:button runat="server" text="<%# ((bool)Eval("IsActive"))?"deactivate":"activate" %>" onclick=" <%# ((bool)Eval(" isactive"))?"activate":"deactivate"="" %="">"/>
there is some error in line two, since it wont compile or run correctly?
Another problem: the button is not part of (or integrated into)the selectedRow. So when control transfers to the De/Activate method, no row is selected!?
It only works if i specifically select a row, and then click the button. Not exactly what i wanted
cheers! Frodi
|
|
|
|
|
this is the only step about I din't speak because it seems clear...
I mean:
The philosophy is not the same as in win32 applications...
when you are in web environement, the only way to know the action to do is to check the parameters (GET and POST) in the querry from the client. you can test those parameters in the page load event and forward to a method according to this parameter.
so, if you give to the button the url "?action=activate", and, in the page load event, you check that the action parameter value is "activate". then you could call the "Activate" method. Do you better understand or do you need some information more about it? (you could find it easily on the web)
Let's make code sharing our goal...
Blaise Braye
|
|
|
|
|
wao what did I smoke yesterday? lol
forget my post, not everything is false but I forgot we are working on .net2
way one:
1. add an id to the body for this exemple: <form id="form1" runat="server">
2. then in the item template add the OnClick attribute.
<asp:TemplateField>
<itemtemplate>
<asp:Button runat="server" OnClick="toggle" PostBackUrl='<%# "?id=" + Eval("Id") %>' Text='<%# ((bool)Eval("IsActive"))?"deactivate":"activate" %>' />
</itemtemplate>
</asp:TemplateField>
3. in behind code, add:
protected void toggle(object sender, EventArgs e)
{
this.BODY.Attributes.Add("bgcolor", "blue");
}
way two:
1. add an id to the body for this exemple: <form id="form1" runat="server">
2.
<dd:GridView runat="server" ID="gdv" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="Id" DataSourceID="objDtsNations" ForeColor="#333333" GridLines="None" OnRowCreated="gdv_RowCreated">
3.
protected void toggle(object sender, EventArgs e)
{
this.BODY.Attributes.Add("bgcolor", "blue");
}
protected void gdv_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btn = (Button)e.Row.Cells[2].Controls[1];
btn.Click += toggle;
}
}
Let's make code sharing our goal...
Blaise Braye
|
|
|
|
|
Tnx Blaise
I have been working with your example for a few days, and now, i finally have what i am looking for. A simple gridview, where some buttons are visible depending upon the status of some variable(e.g. isActive). My goal was to get have an Activate button in case of the variable being false and vice versa.
Kindly Frodi, Denmark
|
|
|
|
|
It's a great job, but i tried it and ContainsLink() don't works fine.
I try to ad a command field with edit and delete commands with the different button types (Link, image and button), but ContainsLink() ever return false, and the result is that edit and delete don't work.
I try to change
if (!Recurser.ContainsLink(cell))
{
...
}
for
if (cell.Controls.Count<=0)
{
...
}
and now it works fine.
|
|
|
|
|
héhé good idea guy
thanks for the tip.
However I am surprised my tip didn't work with you...
Anyway, I'll prefer the your for now
Let's make code sharing our goal...
Blaise Braye
|
|
|
|
|
Man this is awesome I have been looking for this for a while this helped me a lot. Hats off
saud
|
|
|
|