|
|
I am doing the following thing
protected void Button1_Click(object sender, EventArgs e)
{
int recordCount;
DataSet ds=(DataSet)GridView1.DataSource;
recordCount = ds.Tables[0].Rows.Count;
Response.Write(recordCount);
}
get error "Object reference not set to an instance of an object." stating ds.Tables[0] is null.
I am not getting why this is happing even i am binding the gridview in page load under if(!IsPostBack).
Thanks,
Sri...
|
|
|
|
|
Suppose GridView is gr
int k=gr.PageSize*(gr.PageCount-1);
gr.Currentpage=gr.PageCount-1;
int p=gr.Rows.Count ;
int GridRows= k+p;
Try this I think you could get with a minor modification
|
|
|
|
|
Thanks Nishant,
You code is fine but we need to find the number of rows in the page of gridview to calculate the total number of rows in grid view. Any idea to find the number of rows in the last page??
Thanks,
Sri...
|
|
|
|
|
Can you try with the paging to false and then check the recordcount after that u can make the paging as true.
|
|
|
|
|
Hi Prasant,
I am doing the following things:
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.AllowPaging = false;
Response.Write(GridView1.PageCount.ToString());
GridView1.AllowPaging = true;
}
Still getting 10 rows as rows on current page.
Thanks,
Sri...
|
|
|
|
|
Hi Srinandan,
Set the page count to Last page
gr.CurrentPageIndex=gr.PageCount-1;
gr.Rows.Count You will get the rows on the last page .
|
|
|
|
|
Hi ,
One of my pages contains master page.I dont want it anymore.Is there anyway to remove it from my page ?
|
|
|
|
|
Subin Mavunkal wrote: One of my pages contains master page.
Remove the ASP:Content Tage. Use Normal HTML Tag like other pages.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
I created a textbox.....
i want to bold text in textbox, suppose this is a text in textbox "My Name is Arun".....so i want "Arun" in bold and rest the same......
Any Help ?
Thanks in advance
|
|
|
|
|
Have you tired with My Name is <b>Arun</b> ?
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
This will not work in a normal textbox control.
|
|
|
|
|
I am afraid it is impossible to do that.
You can use other controls or div with <b></b>.
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 21:48pm.
|
|
|
|
|
As far as i know, you cannot do this in a normal textbox control.
Try to use some HTML Editor control.
|
|
|
|
|
Hi All,
I am designing the new project.
My question how to maintain the navigation.
Suppose I have to write in page
Response.Redirest("Setting.aspx");
but what my page name changes.
so i have to change every where.
Can u suggest any idea to solve problem.ony way is through class. is there any better way.
Thanks and regards,
Amit Patel
|
|
|
|
|
If you are mentioning the page name and if it changed then you have to change every where. You can also pass page name as argument.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
if you are using Master Pages then you can only change it in one place. here is more info about master pages
http://www.asp.net/Learn/master-pages/[^]
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi,
you can try Server.transfer("Setting.aspx");
modified 27-May-14 5:11am.
|
|
|
|
|
Hi to all,
I am using DetailsView control to edit the details of the user. But when I click the Edit button, the update button is not clickable. I am unable to find out the problem.
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" <br />
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" <br />
GridLines="None" Height="50px" Width="364px" <br />
AutoGenerateEditButton="True" DataKeyNames="UserId" <br />
style="margin-right: 0px" onitemupdating="DetailsView1_ItemUpdating"><br />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /><br />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" /><br />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" /><br />
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" /><br />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /><br />
<Fields><br />
<asp:BoundField DataField="UserId" HeaderText="UserId" ReadOnly="True" SortExpression="UserId" /><br />
<asp:BoundField DataField="first_name" HeaderText="first_name" SortExpression="first_name" /><br />
<asp:BoundField DataField="last_name" HeaderText="last_name" SortExpression="last_name" /><br />
<asp:BoundField DataField="AddressLine1" HeaderText="address1" SortExpression="AddressLine1" /><br />
<asp:BoundField DataField="AddressLine2" HeaderText="address2" SortExpression="AddressLine2" /><br />
<asp:BoundField DataField="AddressLine3" HeaderText="address3" SortExpression="AddressLine3" /><br />
<asp:BoundField DataField="zipcode" HeaderText="zipcode" SortExpression="zipcode" /><br />
<asp:BoundField DataField="city" HeaderText="city" SortExpression="city" /><br />
<asp:BoundField DataField="state" HeaderText="state" SortExpression="state" /><br />
<asp:BoundField DataField="country" HeaderText="country" SortExpression="country" /><br />
<asp:BoundField DataField="landline" HeaderText="landline" SortExpression="landline" /><br />
<asp:BoundField DataField="mobile" HeaderText="mobile" SortExpression="mobile" /><br />
</Fields><br />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /><br />
<EditRowStyle BackColor="#999999" /><br />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" /><br />
</asp:DetailsView><br />
<br /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" <br />
ConnectionString="<%$ ConnectionStrings:newcon %>" <br />
<br />
SelectCommand="SELECT [First_Name], [State], [City], [AddressLine3], [AddressLine2], [AddressLine1], [Last_Name], [Country], [Landline], [Zipcode], [Mobile],[UserId] FROM [USERS] WHERE ([UserId] = @UserId)"<br />
UpdateCommand="UPDATE [USERS] SET [First_Name] = @First_Name, [State] = @State, [City] = @City, [AddressLine3] = @AddressLine3, [AddressLine2] = @AddressLine2, [AddressLine1] = @AddressLine1, [Last_Name] = @Last_Name, [Country] = @Country, [Landline] = @Landline, [Zipcode] = @Zipcode, [Mobile] = @Mobile WHERE [UserId] = @UserId" ><br />
<br />
<SelectParameters><br />
<asp:Parameter Name="UserId" /><br />
</SelectParameters><br />
<UpdateParameters><br />
<asp:Parameter Name="UserId" /><br />
<asp:Parameter Name="First_Name" Type="String" /><br />
<asp:Parameter Name="State" Type="String" /><br />
<asp:Parameter Name="City" Type="String" /><br />
<asp:Parameter Name="AddressLine3" Type="String" /><br />
<asp:Parameter Name="AddressLine2" Type="String" /><br />
<asp:Parameter Name="AddressLine1" Type="String" /><br />
<asp:Parameter Name="Last_Name" Type="String" /><br />
<asp:Parameter Name="Country" Type="String" /><br />
<asp:Parameter Name="Landline" Type="String" /><br />
<asp:Parameter Name="Zipcode" Type="String" /><br />
<asp:Parameter Name="Mobile" Type="String" /><br />
</UpdateParameters><br />
</asp:SqlDataSource><br />
cheers,
sneha
|
|
|
|
|
Hi Sneha ,
Be little more specific what is the problem
|
|
|
|
|
Hi Nishant,
In the edit mode of the details view we have two buttons, update and cancel.
Cancel is working fine. But the update button is not working.It is not clickable. Nothing is happening when I click on it.
I even created a new page and applied the same code but of no use. I used details view several times but this time I am not able to solve the problem. If it is not updating the data, I can understand but the update button is not clickable is a strange behaviour.
cheers,
sneha
|
|
|
|
|
Got the problem .....but not sure what exactly is causing the problem ,
Have u associated any event with update Command , or just check anywhere it is getting disabled or something in Control Render events.
|
|
|
|
|
I checked the page source. I think here is the problem. The update button is this:
<br />
<a href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$DetailsView1$ctl12", "", true, "", "", false, true))" style="color:#333333;">Update</a><br />
I think it should be:
<br />
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$DetailsView1$ctl12','')" style="color:Black;">Update</a><br />
cheers,
sneha
|
|
|
|
|
sneha Choudhary wrote: But the update button is not working.
oops ..! Sorry You Used the other way which you cant keep break point i didnt check it..!
LatestArticle :Log4Net
Why Do Some People Forget To Mark as Answer .If It Helps.
|
|
|
|
|
I have a big GridView (with, edit,update,delete and insert operations),(forgive all this code, I cant present my problem other way
The template field is like this: (the gridview has OnPageIndexChanging="GridView3_PageIndexChanging" OnSorting="GridView3_Sorting" AllowSorting="True" properties)
<asp:TemplateField HeaderText="Nome" SortExpression="Nome">
<EditItemTemplate>
<asp:TextBox ID="txtname" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblname" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNName" runat="server" width="75px" Visible='<%# (bool) show_hide_insert() %>'> </asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
The Grid View is populated this way:
public void TempTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(String));
dt.Columns.Add("Year", typeof(String));
dt.Columns.Add("Image", typeof(String));
Session["data"] = dt;
Temp = dt.Copy();
DataSet ds = GetData(query);
GridView3.DataSource = ds;
GridView3.DataBind();
}
DataSet GetData(String queryString)
{
string connectionString;
connectionString = WebConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;
DataSet ds = new DataSet();
try
{
SqlConnection Conn = new SqlConnection(connectionString);
SqlDataAdapter adapter = new SqlDataAdapter(queryString, connectionString);
adapter.Fill(ds);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return ds;
}
public DataTable Temp
{
get
{
object o = ViewState["Temp"];
if (o == null)
{
DataTable dt = new DataTable();
return dt;
}
else
return (DataTable)o;
}
set
{
ViewState["Temp"] = value;
}
}
And then I'm trying to sort this way:
private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
return newSortDirection;
}
protected void GridView3_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView3.PageIndex = e.NewPageIndex;
GridView3.DataBind();
}
protected void GridView3_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = GridView3.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
GridView3.DataSource = dataView;
GridView3.DataBind();
}
}
I think its because I'm using the temporary table, but dont know how to aply that here on sorting... Can you help me please?
|
|
|
|