radio button in datalist

V

Vikas Kumar

i had coded like this

<ItemTemplate>
<table width="100%">
<tr width="100%">
<td
width="25%"><%#DataBinder.Eval(Container.DataItem,"FName")%></td>
<td width="25%"><input type=text name="txtPass"
value='<%#DataBinder.Eval(Container.DataItem,"Passwd")%>'></td>
<td width="45%" align="left">
<asp:RadioButton ID="rb1" runat="server" GroupName="gp1"
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="rb2" runat="server" GroupName="gp1"
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="rb3" Runat="server" GroupName="gp1"
/>

</td>
<td width="5%" align="left">
<asp:Button ID="EditSubuser" Text="Edit"
Runat="server"></asp:Button></td>
</tr>
</table>
</ItemTemplate>

and in code behind
protected void listUser_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)

{

DataRowView drv = e.Item.DataItem as DataRowView;

RadioButton rb1 = (RadioButton)e.Item.FindControl("rb1");

RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");

RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");


}

its working fine till here
but how will i select one of these three now
the code below selects 1,2 or 3 from permission colomn
how will i take value from permission coloumn and will set one of these
three rd1 or rd2 or rd3

string strsql="select
Userinfo.UID,Userinfo.FName,Userinfo.Permission,UserPassword.Passwd from
Userinfo,UserPassword where Userinfo.UID=UserPassword.UID and
Userinfo.ParentID="+ userid;

Database db=DatabaseFactory.CreateDatabase();

DBCommandWrapper cmd=db.GetSqlStringCommandWrapper(strsql);

dr=db.ExecuteReader(cmd);

listUser.DataSource=dr;

listUser.DataBind();

dr.Close();
 
S

Steven Cheng[MSFT]

Hi Vikas,

Thank you for posting.

As for the issue, I've posted my new response in your former thread, for
your convenience, I'll repaste the response here:

============================
Thanks for your response Vikas,

Since you've got the DataRowView object in ItemDataBound event, then you
can query the certain column(select through dataReader in database) value
from it, e.g:

=================================
protected void listUser_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)

{

DataRowView drv = e.Item.DataItem as DataRowView;


int selval = (int)drv["selectvalue"];

RadioButton rb1 = (RadioButton)e.Item.FindControl("rb1");

RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");

RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");


}
====================

DataRowView is just somewhat like DataRow, you can access those database
column's value through index or name:

#DataRowView Class
http://msdn2.microsoft.com/en-us/library/system.data.datarowview(VS.80).aspx

Then, you can set certain RadioButton's Checked property to false or true
based on the column's value.

Hope this helps. If you still have anything unclear, please feel free to
post here.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

Also, if you feel it proper that we continue to discuss in the original
thread, please feel free to post there.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
V

Vikas Kumar

I had already tried thid code
protected void listUser_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)

{

DataRowView drv = e.Item.DataItem as DataRowView;

RadioButton rb1 = (RadioButton)e.Item.FindControl("rb1");

RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");

RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");

int setperm = (int)drv["Permission"];


i am getting following error


--------------------------------------------------------------------------------


Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


Line 80: RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");
Line 81: RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");
Line 82: int setperm = (int)drv["Permission"];
Line 83:
Line 84:


Source File: d:\ankit\property\user\manageuser.aspx.cs Line: 82

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
property.user.manageuser.listUser_ItemDataBound(Object sender,
DataListItemEventArgs e) in d:\ankit\property\user\manageuser.aspx.cs:82
System.Web.UI.WebControls.DataList.OnItemDataBound(DataListItemEventArgs
e)
System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem)
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
property.user.manageuser.Page_Load(Object sender, EventArgs e) in
d:\ankit\property\user\manageuser.aspx.cs:48
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


and same error i get if i write rb1.Checked=true;
for rb1

Steven Cheng said:
Hi Vikas,

Thank you for posting.

As for the issue, I've posted my new response in your former thread, for
your convenience, I'll repaste the response here:

============================
Thanks for your response Vikas,

Since you've got the DataRowView object in ItemDataBound event, then you
can query the certain column(select through dataReader in database) value
from it, e.g:

=================================
protected void listUser_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)

{

DataRowView drv = e.Item.DataItem as DataRowView;


int selval = (int)drv["selectvalue"];

RadioButton rb1 = (RadioButton)e.Item.FindControl("rb1");

RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");

RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");


}
====================

DataRowView is just somewhat like DataRow, you can access those database
column's value through index or name:

#DataRowView Class
http://msdn2.microsoft.com/en-us/library/system.data.datarowview(VS.80).aspx

Then, you can set certain RadioButton's Checked property to false or true
based on the column's value.

Hope this helps. If you still have anything unclear, please feel free to
post here.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

Also, if you feel it proper that we continue to discuss in the original
thread, please feel free to post there.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no
rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
V

Vikas Kumar

Thanks for reply Sir
I tried like this now
DataRowView drv = e.Item.DataItem as DataRowView;

RadioButton rb1 = (RadioButton)e.Item.FindControl("rb1");

RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");

RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");

if(drv["Permission"] == null)

{

Response.Write("hell");

}



it gives error on line-if(drv["Permission"] == null

i checked it putting break pts it gives error on this if statement only

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 80: RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");
Line 81: RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");
Line 82: if(drv["Permission"] == null)
Line 83: {
Line 84: Response.Write("hell");

Source File: d:\ankit\property\user\manageuser.aspx.cs Line: 82

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
property.user.manageuser.listUser_ItemDataBound(Object sender,
DataListItemEventArgs e) in d:\ankit\property\user\manageuser.aspx.cs:82
System.Web.UI.WebControls.DataList.OnItemDataBound(DataListItemEventArgs
e)
System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem)
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
property.user.manageuser.Page_Load(Object sender, EventArgs e) in
d:\ankit\property\user\manageuser.aspx.cs:49
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

Vikas Kumar said:
I had already tried thid code
protected void listUser_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)

{

DataRowView drv = e.Item.DataItem as DataRowView;

RadioButton rb1 = (RadioButton)e.Item.FindControl("rb1");

RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");

RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");

int setperm = (int)drv["Permission"];


i am getting following error


--------------------------------------------------------------------------------


Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


Line 80: RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");
Line 81: RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");
Line 82: int setperm = (int)drv["Permission"];
Line 83:
Line 84:


Source File: d:\ankit\property\user\manageuser.aspx.cs Line: 82

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
property.user.manageuser.listUser_ItemDataBound(Object sender,
DataListItemEventArgs e) in d:\ankit\property\user\manageuser.aspx.cs:82
System.Web.UI.WebControls.DataList.OnItemDataBound(DataListItemEventArgs
e)
System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem)
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
property.user.manageuser.Page_Load(Object sender, EventArgs e) in
d:\ankit\property\user\manageuser.aspx.cs:48
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


and same error i get if i write rb1.Checked=true;
for rb1

Steven Cheng said:
Hi Vikas,

Thank you for posting.

As for the issue, I've posted my new response in your former thread, for
your convenience, I'll repaste the response here:

============================
Thanks for your response Vikas,

Since you've got the DataRowView object in ItemDataBound event, then you
can query the certain column(select through dataReader in database) value
from it, e.g:

=================================
protected void listUser_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)

{

DataRowView drv = e.Item.DataItem as DataRowView;


int selval = (int)drv["selectvalue"];

RadioButton rb1 = (RadioButton)e.Item.FindControl("rb1");

RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");

RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");


}
====================

DataRowView is just somewhat like DataRow, you can access those database
column's value through index or name:

#DataRowView Class
http://msdn2.microsoft.com/en-us/library/system.data.datarowview(VS.80).aspx

Then, you can set certain RadioButton's Checked property to false or true
based on the column's value.

Hope this helps. If you still have anything unclear, please feel free to
post here.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

Also, if you feel it proper that we continue to discuss in the original
thread, please feel free to post there.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no
rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
V

Vikas Kumar

my data source is datareader

string strsql="select UID,FName,Permission,Email1 from Userinfo where
ParentID="+ userid;

Database db=DatabaseFactory.CreateDatabase();

DBCommandWrapper cmd=db.GetSqlStringCommandWrapper(strsql);

dr = db.ExecuteReader(cmd);

listUser.DataSource=dr;

listUser.DataBind();

dr.Close();

Vikas Kumar said:
Thanks for reply Sir
I tried like this now
DataRowView drv = e.Item.DataItem as DataRowView;

RadioButton rb1 = (RadioButton)e.Item.FindControl("rb1");

RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");

RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");

if(drv["Permission"] == null)

{

Response.Write("hell");

}



it gives error on line-if(drv["Permission"] == null

i checked it putting break pts it gives error on this if statement only

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 80: RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");
Line 81: RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");
Line 82: if(drv["Permission"] == null)
Line 83: {
Line 84: Response.Write("hell");

Source File: d:\ankit\property\user\manageuser.aspx.cs Line: 82

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
property.user.manageuser.listUser_ItemDataBound(Object sender,
DataListItemEventArgs e) in d:\ankit\property\user\manageuser.aspx.cs:82
System.Web.UI.WebControls.DataList.OnItemDataBound(DataListItemEventArgs
e)
System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem)
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
property.user.manageuser.Page_Load(Object sender, EventArgs e) in
d:\ankit\property\user\manageuser.aspx.cs:49
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

Vikas Kumar said:
I had already tried thid code
protected void listUser_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)

{

DataRowView drv = e.Item.DataItem as DataRowView;

RadioButton rb1 = (RadioButton)e.Item.FindControl("rb1");

RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");

RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");

int setperm = (int)drv["Permission"];


i am getting following error


--------------------------------------------------------------------------------


Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set
to an instance of an object.

Source Error:


Line 80: RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");
Line 81: RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");
Line 82: int setperm = (int)drv["Permission"];
Line 83:
Line 84:


Source File: d:\ankit\property\user\manageuser.aspx.cs Line: 82

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
property.user.manageuser.listUser_ItemDataBound(Object sender,
DataListItemEventArgs e) in d:\ankit\property\user\manageuser.aspx.cs:82

System.Web.UI.WebControls.DataList.OnItemDataBound(DataListItemEventArgs
e)
System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem)
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
property.user.manageuser.Page_Load(Object sender, EventArgs e) in
d:\ankit\property\user\manageuser.aspx.cs:48
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


and same error i get if i write rb1.Checked=true;
for rb1

Steven Cheng said:
Hi Vikas,

Thank you for posting.

As for the issue, I've posted my new response in your former thread, for
your convenience, I'll repaste the response here:

============================
Thanks for your response Vikas,

Since you've got the DataRowView object in ItemDataBound event, then you
can query the certain column(select through dataReader in database)
value
from it, e.g:

=================================
protected void listUser_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)

{

DataRowView drv = e.Item.DataItem as DataRowView;


int selval = (int)drv["selectvalue"];

RadioButton rb1 = (RadioButton)e.Item.FindControl("rb1");

RadioButton rb2 = (RadioButton)e.Item.FindControl("rb2");

RadioButton rb3=(RadioButton)e.Item.FindControl("rb3");


}
====================

DataRowView is just somewhat like DataRow, you can access those database
column's value through index or name:

#DataRowView Class
http://msdn2.microsoft.com/en-us/library/system.data.datarowview(VS.80).aspx

Then, you can set certain RadioButton's Checked property to false or
true
based on the column's value.

Hope this helps. If you still have anything unclear, please feel free to
post here.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

Also, if you feel it proper that we continue to discuss in the original
thread, please feel free to post there.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no
rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top